![Page 1: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/1.jpg)
Custom Post Types
Choose Your Own Adventure
WordCamp Atlanta 15 March 2014Evan Mullins @circlecube
WordPress is for more than just blogging. Create and manage more types of content, like a portfolio, events, testimonials, images, people, cats anything you can think of you’d like to have a website about. Learn how to add content types like they were built in.
![Page 2: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/2.jpg)
Who am I?
I’ve been using WordPress since late 2005, that’s WP 2.0! First I knew WordPress as a blogger, then as designer, then front-end coder and since as a theme and plug-in developer. I’m the Interactive Director at Brand Fever, an Atlanta-based brand & marketing agency, where I get a kick out of developing sites in WordPress every day! I see WordPress as a flexible, user-friendly option that is nearly always the best tool for the job. I most enjoy playing with custom fields and custom post types to create simple CMS solutions to complex problems and making them responsive & interactive. When not programming, I’m likely busy as a soccer coach, boy scout leader or playing with my family: My awesome wife & our 3 boys (daughter on the way) and our lab-hound mutt. I like pizza and chocolate.
Evan Mullinscirclecube.com
![Page 3: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/3.jpg)
Post Types
![Page 4: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/4.jpg)
Introducing: Post Types
WordPress can hold and display many different types of content. A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored in the same place, in the wp_posts database table, but are differentiated by a column called post_type.
WordPress 3.0 gives you the capability to add your own custom post types and to use them in different ways.
![Page 5: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/5.jpg)
Posts
Posts in WordPress refer to the blog content. Each blog post is a “post”. But all other content is also a post. I try to distinguish by always calling blog posts, “blog posts” or “Posts” and using the term “post” as a more abstract term.
![Page 6: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/6.jpg)
Pages
WordPress pages are not time based like blog posts but would be best located in your main navigation. Things like your “about” page or your “contact” page. Pages are posts of post_type page.
Pages can select templates to be used so you can customize the layout and you can customize the content using custom fields.
![Page 7: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/7.jpg)
Etc
Attachment (Post Type: 'attachment')
Revision (Post Type: 'revision')
Navigation menu (Post Type: 'nav_menu_item')
![Page 8: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/8.jpg)
WordPress NIB - Default post types
![Page 9: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/9.jpg)
Introducing:Custom Post Types
Custom post types are new post types you can create. A custom post type can be added to WordPress via the register_post_type() function. This function allows you to define a new post type by its labels, supported features, availability and other specifics.
http://codex.wordpress.org/Post_Types#Custom_Post_Types
![Page 10: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/10.jpg)
What are they used for?
ProductsPortfolio WorksEventsTestimonialsPress ReleasesMoviesBooksStarsGolf Courses
CarsSongsRecipesBlocksPeopleCatsGames
etc...
![Page 11: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/11.jpg)
http://locallylost.com/pop/about-2/
![Page 12: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/12.jpg)
http://www.brandfeverinc.com/portfolio/
![Page 13: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/13.jpg)
![Page 14: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/14.jpg)
CPT
Custom post types for different types of data or content that you’d manage in a website.
(Queue Devil’s Advocate)But, we have that already right?
Categories, tags, post formats …Posts, pages ...
![Page 15: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/15.jpg)
When to use?
Formats vs Taxonomies vs CPT
![Page 16: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/16.jpg)
Taxonomies
Taxonomy is a way to group things together.
Built in taxonomies are categories and tags. But we can create custom taxonomies as well!
http://codex.wordpress.org/Taxonomies
![Page 17: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/17.jpg)
Taxonomy ≠ CPT
If you just want to organize or categorize your content, a CPT is not the answer. Use a taxonomy.
![Page 18: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/18.jpg)
Post Formats
A Post Format is a formatting designation made to a post. A piece of meta information that can be used by a theme to customize the presentation (or format) of a post.
The Post Formats feature provides a standardized list of formats that are available to all themes that support the feature.
http://codex.wordpress.org/Post_Formats
http://markjaquith.wordpress.com/2010/11/12/post-formats-vs-custom-post-types/
![Page 19: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/19.jpg)
Post Formats ≠ CPT
If your aim is to just display blog content but display each ‘type’ of blog post differently, you might rather use Post Formats.
![Page 20: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/20.jpg)
When to use?
Posts vs Pages vs CPT
![Page 21: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/21.jpg)
(Blog) Posts
Post in WordPress is a post type that is typical for and most used by blogs. Posts are normally displayed in a blog in reverse chronological order. Posts are also used for creating the feeds.
Posts usually have comments enabled and contain a title and body text. They can be organized via taxonomy and formatted via Post Formats.
![Page 22: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/22.jpg)
Posts ≠ posts (CPT)
Blog posts belong to the blog section of your site. If you need any other type of content. You have to create it via CPT.
![Page 23: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/23.jpg)
Pages ≠ CPT
I hope this one is obvious.
Pages in WordPress are posts, but not part of the blog
posts or Posts. Pages can use different page templates
to display them. Pages can also be organized in a
hierarchical structure, with pages being parents to
other pages, but they normally cannot be assigned
categories and tags.
![Page 24: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/24.jpg)
Choose Your Own
CPT come with many options/arguments:
label(s), description, public, exclude_from_search,
publicly_queryable, show_ui, show_in_nav_menu,
show_in_menu, show_in_admin_bar, menu_position,
capability_type, capabilities, map_meta_cap, hierarchical,
supports, register_meta_box_cb, taxonomies, has_archive,
permalink_epmask, rewrite, query_var, can_export.
![Page 25: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/25.jpg)
How to
![Page 26: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/26.jpg)
How to create a CPT : 1 of 3
Code it yourself:
add_action( 'init', 'create_post_type' );function create_post_type() {
register_post_type( 'acme_product',array(
'labels' => array('name' => __( 'Products' ),'singular_name' => __( 'Product' )
),'public' => true,'has_archive' => true, ...)
);}
![Page 27: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/27.jpg)
Program it where?(queue debate: theme vs plugin)
![Page 28: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/28.jpg)
Hooks
Hooks are provided by WordPress to allow you to 'hook into' the rest of WordPress. That is, your functions hook into WordPress functions. Then when the WordPress functions are called at any time, it sets your code in motion.
![Page 29: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/29.jpg)
Hooks
actionsActions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points, using the Action API.
filtersFilters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Your plugin can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API.
![Page 30: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/30.jpg)
How to Create CPT: 2 of 3
Use a tool to write the code for you.
![Page 31: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/31.jpg)
GenerateWP.com
http://generatewp.com/post-type/
![Page 32: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/32.jpg)
Themergency.com
http://themergency.com/generators/wordpress-custom-post-types/
![Page 33: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/33.jpg)
How to Create CPT: 3 of 3
Use a plugin to manage your custom post types.
Any favorites out there?
![Page 34: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/34.jpg)
Custom Post Type UI
http://wordpress.org/plugins/custom-post-type-ui/
![Page 35: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/35.jpg)
Types
http://wordpress.org/plugins/types/
![Page 36: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/36.jpg)
PIKLIST
http://wordpress.org/plugins/piklist/
![Page 37: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/37.jpg)
WP Easy Post Types
http://wordpress.org/plugins/easy-post-types/
![Page 38: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/38.jpg)
MasterPress
http://masterpressplugin.com/
![Page 39: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/39.jpg)
Now What?
You’ve decided what post types you want.You’ve decided how to add them.
Add your recipe post type.Add all your favorite recipes as content.
Most likely though, your custom post type needs custom content, no? A recipe has different data than the default title + body.
![Page 40: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/40.jpg)
And Then?
How to customize content for the custom post type?
How to display customized content for the custom post type?
![Page 41: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/41.jpg)
Custom Fields
Again 3 ways:1. Write your own.2. Use a tool to help you write it.3. Use a plugin.
![Page 42: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/42.jpg)
Custom Fields: 1 of 3
Roll your own. Use the built-in custom fields to add these values to your content.
![Page 43: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/43.jpg)
Custom Fields: 1 of 3
![Page 44: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/44.jpg)
Custom Fields: 1 of 3
<?php the_meta(); ?>
<?php $key="mykey"; echo get_post_meta($post->ID, $key, true); ?>
Then, set up your template files for this custom post type to display the fields.
![Page 45: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/45.jpg)
Theme Template Hierarchy
Which template file(s) will WordPress use when it displays a certain type of page?
The huge logic tree (diagram) that helps WordPress decide which template to show for every type of content. It shows the defaults and fallbacks, notice how everything defaults back to index as a fallback if that specific type of content does not have a template.
![Page 46: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/46.jpg)
https://codex.wordpress.org/Template_Hierarchy
![Page 47: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/47.jpg)
Template Files for CPTs
single-$posttype.php
single-recipe.php will be used instead of the default single.php file for this CPT.
archive-$posttype.php
archive-recipe.php will be used instead of the default archive.php file for this CPT.
![Page 48: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/48.jpg)
Custom Fields: 2 of 3
Use a tool/library/generator to support/write your code.
Custom Metaboxes and Fields for WordPressby WebDevStudios on github
any other shout outs?
![Page 49: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/49.jpg)
https://github.com/webdevstudios/Custom-Metaboxes-and-Fields-for-WordPress
![Page 50: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/50.jpg)
![Page 51: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/51.jpg)
Custom Fields: 3 of 3
Use a plugin. I recommend my all-time favorite plugin EVER:
Advanced Custom Fields by mate Elliot Condon
any other shout outs?
![Page 52: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/52.jpg)
http://www.advancedcustomfields.com/ http://wordpress.org/extend/plugins/advanced-custom-fields/
![Page 53: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/53.jpg)
![Page 54: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/54.jpg)
![Page 55: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/55.jpg)
![Page 56: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/56.jpg)
<?php the_field(‘field_name’); ?>
<?php get_field(‘field_name’); ?>
![Page 57: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/57.jpg)
![Page 58: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/58.jpg)
Additional Reading:
http://codex.wordpress.org/Post_Types#Custom_Post_Types
http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress
http://wp.smashingmagazine.com/2012/11/08/complete-guide-custom-post-types/
![Page 59: Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan Mullins](https://reader033.vdocuments.mx/reader033/viewer/2022051613/54c714a94a795928408b46de/html5/thumbnails/59.jpg)
Thank You! Any Questions?
Slides @ http://circlecube.com/wordpress/
Evan Mullinscirclecube.com