SlideShare a Scribd company logo
1 of 36
Creatively Creating
Custom Post Types
NikhilVimal
#WordUpMPLS
Hi, I’m Nikhil
• I develop with WordPress
• I can be found on Twitter @TechVoltz
• This my first talk ever
Custom Post Types?
They Rock (Seriously)
But what are they?
•Instead of using default posts and categories in
WordPress, use Custom Post Types
•You can add a lot of cool things that are not in a
Default WordPress install
•Added in WordPress 3.0
Why Do You need
them?
Organization
Portfolio
Post Type could be paintings
Online Store
Post Type could be Products
Your only limitation is
Your imagination
“WordPress can hold and display many
different types of content.”
-WordPress Codex
But how do we add
Custom Post Types?
With a plugin of course
Create a file called myposttype.php
<?php
/**
* Plugin Name: Your Custom Post Type
* Plugin URI: http://yourpluginswebsite.com
* Description: A brief description of your Plugin.
* Version: The Plugin's Version Number, e.g.: 1.0
* Author: Your Name
* Author URI: http://yourwebsite.com
* License: A "Slug" license name e.g. GPL2
*/
add_action('init', 'wordup_sessions');
function wordup_sessions() {
$wordup_args = array(
'public' => true,
'has_archive' => true,
'query_var' => 'wordup',
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'labels' => array(
'name' => 'WordUp Sessions',
'singular' => 'WordUp Session',
'add_new' => 'Add Session',
'add_new_item' => 'Add Session',
'edit_item' => 'Edit Session',
'new_item' => 'New Session',
'view_item' => 'View Session',
'search_items' => 'Search WordUp',
'not_found' => 'No sessions found',
'not_found_in_trash' => 'No Sessions found in the Trash',
),
);
register_post_type('WordUp', $wordup_args );
}
Lets examine all the
code!!
add_action('init', 'wordup_sessions');
function wordup_sessions() {
$wordup_args = array(
'public' => true,
'has_archive' => true,
'query_var' => 'wordup',
'menu_position' => 5,
'supports' => array( 'title', 'editor',
'thumbnail', 'excerpt', 'comments' ),
'labels' => array(
'name' => 'WordUp Sessions',
'singular' => 'WordUp Session',
'add_new' => 'Add Session',
'add_new_item' => 'Add Session',
'edit_item' => 'Edit Session',
'new_item' => 'New Session',
'view_item' => 'View Session',
'search_items' => 'Search Sessions',
'not_found' => 'No sessions found',
'not_found_in_trash' => 'No Sessions found in the
Trash',
),
register_post_type('WordUp', $wordup_args );
}
Styling your CPT Page
With single-$posttype.php
Having an Archive Page
for your CPT
With archive-$posttype.php
Taxonomies
More Organization
“Basically, a taxonomy is a way to
group things together”
-WordPress Codex
Taxonomies
Categories and Tags
Portfolio
Taxonomy is oil painting
After our Custom Post
type function….
add_action('init', 'wordup_tracks');
function wordup_tracks(){
$track_args = array(
'hierarchical' => true,
'query_var' => ‘wordup_tracks',
'show_tagcloud' => true,
'labels' => array(
'name' => 'Tracks',
'edit_item' => 'Edit Track',
'update_item' => 'Update Track',
'add_new_item' => 'Add New Track',
'new_item_name' => 'New Track',
'all_items' => 'All Tracks',
'search_items' => 'Search Tracks',
'popular_items' => 'Popular Tracks',
'add_or_remove_items' => 'Add or remove Tracks',
'choose_from_most_used' => 'Choose from most used Tracks',
),
);
register_taxonomy(‘wordup_tracks',
array('wordup'), $dev_args);
}
The array(‘wordup’) is our custom post type
You can add more
Like Custom Fields
Questions?
Resources
• http://justintadlock.com/archives/2010/04/29/custom-post-types-in-
wordpress
• http://codex.wordpress.org/Post_Types
• http://codex.wordpress.org/Taxonomies
• http://wp.smashingmagazine.com/2012/11/08/complete-guide-
custom-post-types/
Thank You!
Nikhil Vimal
@TechVoltz

More Related Content

What's hot (12)

php (Hypertext Preprocessor)
php (Hypertext Preprocessor)php (Hypertext Preprocessor)
php (Hypertext Preprocessor)
 
Pemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan SessionPemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan Session
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHPAdd edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHP
 
12. CodeIgniter vederea inregistrarilor2
12. CodeIgniter vederea inregistrarilor212. CodeIgniter vederea inregistrarilor2
12. CodeIgniter vederea inregistrarilor2
 
Country State City Dropdown in PHP
Country State City Dropdown in PHPCountry State City Dropdown in PHP
Country State City Dropdown in PHP
 
Pagination in PHP
Pagination in PHPPagination in PHP
Pagination in PHP
 
php $_GET / $_POST / $_SESSION
php  $_GET / $_POST / $_SESSIONphp  $_GET / $_POST / $_SESSION
php $_GET / $_POST / $_SESSION
 
Add loop shortcode
Add loop shortcodeAdd loop shortcode
Add loop shortcode
 
WordPress for developers - phpday 2011
WordPress for developers -  phpday 2011WordPress for developers -  phpday 2011
WordPress for developers - phpday 2011
 
jQuery Awesomesauce
jQuery AwesomesaucejQuery Awesomesauce
jQuery Awesomesauce
 
Pemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQLPemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQL
 
bcgr3-jquery
bcgr3-jquerybcgr3-jquery
bcgr3-jquery
 

Similar to Creatively creating custom post types!

Extending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post TypesExtending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post Types
Utsav Singh Rathour
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
Yoav Farhi
 
Building a Portfolio With Custom Post Types
Building a Portfolio With Custom Post TypesBuilding a Portfolio With Custom Post Types
Building a Portfolio With Custom Post Types
Alex Blackie
 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post Types
K.Adam White
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
references
 
Bending word press to your will
Bending word press to your willBending word press to your will
Bending word press to your will
Tom Jenkins
 
Mongo and Harmony
Mongo and HarmonyMongo and Harmony
Mongo and Harmony
Steve Smith
 

Similar to Creatively creating custom post types! (20)

Extending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post TypesExtending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post Types
 
Custom Post Types and Meta Fields
Custom Post Types and Meta FieldsCustom Post Types and Meta Fields
Custom Post Types and Meta Fields
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 
Building a Portfolio With Custom Post Types
Building a Portfolio With Custom Post TypesBuilding a Portfolio With Custom Post Types
Building a Portfolio With Custom Post Types
 
Intro to WordPress theme development
Intro to WordPress theme developmentIntro to WordPress theme development
Intro to WordPress theme development
 
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...
 
How To Write a WordPress Plugin
How To Write a WordPress PluginHow To Write a WordPress Plugin
How To Write a WordPress Plugin
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
 
Custom Post Types in WP3
Custom Post Types in WP3Custom Post Types in WP3
Custom Post Types in WP3
 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post Types
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
Now That's What I Call WordPress Security 2010
Now That's What I Call WordPress Security 2010Now That's What I Call WordPress Security 2010
Now That's What I Call WordPress Security 2010
 
Bending word press to your will
Bending word press to your willBending word press to your will
Bending word press to your will
 
Custom Post Type - Create and Display
Custom Post Type - Create and DisplayCustom Post Type - Create and Display
Custom Post Type - Create and Display
 
Surviving the Zombie Apocalypse using Custom Post Types and Taxonomies
Surviving the Zombie Apocalypse using Custom Post Types and TaxonomiesSurviving the Zombie Apocalypse using Custom Post Types and Taxonomies
Surviving the Zombie Apocalypse using Custom Post Types and Taxonomies
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Mongo and Harmony
Mongo and HarmonyMongo and Harmony
Mongo and Harmony
 
Custom Fields & Custom Metaboxes Overview
Custom Fields & Custom Metaboxes OverviewCustom Fields & Custom Metaboxes Overview
Custom Fields & Custom Metaboxes Overview
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Creatively creating custom post types!

Editor's Notes

  1. (If you’re curious, I am 5,230 days old)
  2. Many different types of combos
  3. This adds an action for your custom post type in the Dashboard, but it will not be there just yet…
  4. ‘Query_var’ Querying posts of this type from the database
  5. ‘query_var’ Is the $posttype
  6. ‘query_var’ is the name of the $posttype
  7. Like a Dewey Decimal system at a public library
  8. Examine all the code!!
  9. This adds an action for your taxonomy in the Dashboard, but it will not be there just yet…
  10. A list of tags
  11. Now we register the taxonomy to our custom post type.
  12. And different kinds of meta data