SlideShare a Scribd company logo
Custom Post types
 in WordPress 3
             Dave Zille
  May 15, 2010 - WordCamp Victoria BC
About Dave
• President, dazil Internet Services
  • WordPress dev, WordPress conversions
   •   web: dazil.com   twitter: @dazil

• Principal, Learn it Today
  • WordPress classroom and online training
   •   web: learnittoday.ca twitter: @learnittodayca
Agenda
•   Custom Post Types:
    •   What are they? What aren’t they?

    •   Why do we need them?

•   Custom Post Type ideas/examples

•   Demo:

    •   Creating a custom post type

    •   Displaying a custom post type

•   Resources
WordPress 3: Not just for Blogs Anymore!

The term “blog” has been
  replaced with “site”
       throughout

WordPress 3 is (officially)
  an actual CMS!

WordPress install process
now asks for “Site Title”
Top 5 Reasons WP is a CMS:
Top 5 Reasons WP is a CMS:

1. Scalability
Top 5 Reasons WP is a CMS:

1. Scalability
2. Security
Top 5 Reasons WP is a CMS:

1. Scalability
2. Security
3. Menu Management
Top 5 Reasons WP is a CMS:

1. Scalability
2. Security
3. Menu Management
4. Custom Taxonomies
Top 5 Reasons WP is a CMS:

1. Scalability
2. Security
3. Menu Management
4. Custom Taxonomies
5. Custom Post Types
What are Custom Post Types?
• Custom Post Types are “content” types
  •   Not to be confused with “blog post”

      •   Traditional “post” is actually just another Custom
          Post Type

  •   Can be used to store and administer different
      types of content on your WordPress site
      •   Traditionally done via plugins (Flutter, Pods, etc)

      •   A huge part of why WP 3 is a CMS
What aren’t Custom Post Types?

• Custom Post Types are not:
  •   A replacement for Custom Fields

      •   (used in conjunction with Custom Fields)

  •   Completely GUI driven

      •   (i.e. cannot be created with default WP GUI)
Why do we need
         Custom Post Types?
• Because Custom Post Types:
 • Make it easy to create and edit different
    forms of content within WordPress
  • Eliminate the need to “fake” custom post
    types by using 3rd party plugins
  • Will make you and your clients happy!
Custom Post Type Examples
• Media:
 • Video, Podcasts
   •   Title,YouTube URL, Length/Duration, Captions,
       Show Notes, etc

• Information:
 • Car for Sale
   •   Make, Model, Color, Features, Pictures, etc..
Custom Post Type Examples
•   Information (cont’d)

    • Real Estate Listing
     •   Price, # bed, # bath, amenities, photos, etc.

    • Gallery/Portfolio
     •   Thumbnail, description, URL, etc.

    • Calendar of Events
     •   Date, time, cost, location, etc.
Your First Custom Post Type
Your First Custom Post Type

•   Case Study:
Your First Custom Post Type

•   Case Study:

    • Recipe database
Your First Custom Post Type

•   Case Study:

    • Recipe database
     •   Description
Your First Custom Post Type

•   Case Study:

    • Recipe database
     •   Description

     •   Ingredients
Your First Custom Post Type

•   Case Study:

    • Recipe database
     •   Description

     •   Ingredients

     •   Prep Time
Your First Custom Post Type

•   Case Study:

    • Recipe database
     •   Description

     •   Ingredients

     •   Prep Time

     •   Cook Time
Custom Post Types: The Code
 •    The register_post_type() function was introduced in
      WordPress 2.9

 •    WordPress 3 makes register_post_type() very useful

 •    Minimal code, and a Custom Post Type is up and running:
add_action( 'init', 'create_recipe_post_type' );

function create_recipe_post_type() {

   register_post_type( 'recipe',

   
   array(

   
   'label' => __( 'Recipes' ),

   
   'singular_label' => __( 'Recipe' ),

   
   'public' => true,

   
   )

   );
}
Custom Post Types: The Code
Custom Post Types: The Code
•   Where does the code go?

    •   2 options:

         •   Create a plugin file, or

         •   add to your theme’s functions.php
Custom Post Types: The Code
•   Where does the code go?

    •   2 options:

            •   Create a plugin file, or

            •   add to your theme’s functions.php

•   This is useful, but can I do more?

    •   The register_post_type() function has 20+ arguments

        •   Can control a lot about CP Types using them

        •   Let’s review some of them..
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments

•   label

    •   A plural descriptive name for the post type

        •   eg “Recipes”

•   singular_label

    •   A singular descriptive name for the post type

        •   eg “Recipe”
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments

•   description

    •   A short descriptive summary of what the post type is

        •   eg. “A set of directions with a list of ingredients for making
            or preparing food.”

•   public

    •   Whether or not the post type should be made available in the
        admin

        •   boolean, default: false
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments

•   menu_position

    •   Allows the positioning of the post type in the admin menu

        •   Default: a new post type is added after Comments

•   menu_icon

    •   Allows you to specify a custom icon for the post type

        •   Default: posts icon
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments
Custom Post Types: The Code
register_post_type() arguments

•   hierarchical
Custom Post Types: The Code
register_post_type() arguments

•   hierarchical

    •   Determines whether the post type is hierarchical (as in ‘pages’),
        or not (as in ‘posts’)
Custom Post Types: The Code
register_post_type() arguments

•   hierarchical

    •   Determines whether the post type is hierarchical (as in ‘pages’),
        or not (as in ‘posts’)

        •   Default: false
Custom Post Types: The Code
register_post_type() arguments

•   hierarchical

    •   Determines whether the post type is hierarchical (as in ‘pages’),
        or not (as in ‘posts’)

        •   Default: false

•   can_export
Custom Post Types: The Code
register_post_type() arguments

•   hierarchical

    •   Determines whether the post type is hierarchical (as in ‘pages’),
        or not (as in ‘posts’)

        •   Default: false

•   can_export

    •   Specifies whether posts of the post type can be exportable using
        WordPress’ export function
Custom Post Types: The Code
register_post_type() arguments

•   hierarchical

    •   Determines whether the post type is hierarchical (as in ‘pages’),
        or not (as in ‘posts’)

        •   Default: false

•   can_export

    •   Specifies whether posts of the post type can be exportable using
        WordPress’ export function

        •   Default: true
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments
Custom Post Types: The Code
register_post_type() arguments

•   supports
Custom Post Types: The Code
register_post_type() arguments

•   supports

    •   Defines what meta boxes and other fields appear when editing
        or creating a post
Custom Post Types: The Code
register_post_type() arguments

•   supports

    •   Defines what meta boxes and other fields appear when editing
        or creating a post

        •   Options: title, editor, comments, trackbacks,
            revisions, author, excerpt, thumbnail, custom-
            fields, page-attributes
Custom Post Types: The Code
register_post_type() arguments

•   supports

    •   Defines what meta boxes and other fields appear when editing
        or creating a post

        •   Options: title, editor, comments, trackbacks,
            revisions, author, excerpt, thumbnail, custom-
            fields, page-attributes

        •   Default: title, editor
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments
Custom Post Types: The Code
register_post_type() arguments

•   register_meta_box_cb
Custom Post Types: The Code
register_post_type() arguments

•   register_meta_box_cb

•   taxonomies
Custom Post Types: The Code
register_post_type() arguments

•   register_meta_box_cb

•   taxonomies

•   capability_type / capabilities
Custom Post Types: Displaying
Custom Post Types: Displaying
•   Customizing the custom post type
    template
Custom Post Types: Displaying
•   Customizing the custom post type
    template

    •   single.php
Custom Post Types: Displaying
•   Customizing the custom post type
    template

    •   single.php

        •   template for the custom post type (default)
Custom Post Types: Displaying
•   Customizing the custom post type
    template

    •   single.php

        •   template for the custom post type (default)

    •   single-post_type_name.php
Custom Post Types: Displaying
•   Customizing the custom post type
    template

    •   single.php

        •   template for the custom post type (default)

    •   single-post_type_name.php

        •   custom template for the custom post type
Custom Post Types: Displaying
•   Customizing the custom post type
    template

    •   single.php

        •   template for the custom post type (default)

    •   single-post_type_name.php

        •   custom template for the custom post type

            •   eg. single-recipe.php
Custom Post Types: Displaying
Custom Post Types: Displaying
•   Displaying custom post types on your site’s
    homepage
Custom Post Types: Displaying
•   Displaying custom post types on your site’s
    homepage

    •   Add to your theme’s functions.php:
Custom Post Types: Displaying
     •   Displaying custom post types on your site’s
         homepage

         •   Add to your theme’s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );
Custom Post Types: Displaying
     •   Displaying custom post types on your site’s
         homepage

         •   Add to your theme’s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {
Custom Post Types: Displaying
     •    Displaying custom post types on your site’s
          homepage

         •   Add to your theme’s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {


   if ( is_home() )
Custom Post Types: Displaying
     •    Displaying custom post types on your site’s
          homepage

         •   Add to your theme’s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {


   if ( is_home() )

   
   $query->set( 'post_type', array( 'post', 'recipe' ) );
Custom Post Types: Displaying
     •    Displaying custom post types on your site’s
          homepage

         •   Add to your theme’s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {


   if ( is_home() )

   
   $query->set( 'post_type', array( 'post', 'recipe' ) );


   return $query;
Custom Post Types: Displaying
     •    Displaying custom post types on your site’s
          homepage

         •   Add to your theme’s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {


   if ( is_home() )

   
   $query->set( 'post_type', array( 'post', 'recipe' ) );


   return $query;
}
Other Custom Post Type Functions
Other Custom Post Type Functions
• Get the “post type” of a post:
Other Custom Post Type Functions
• Get the “post type” of a post:
  •   get_post_type() allows you to check the post type of a
      specific post
Other Custom Post Type Functions
• Get the “post type” of a post:
    •    get_post_type() allows you to check the post type of a
         specific post
$post_type = get_post_type($post_id);
Other Custom Post Type Functions
• Get the “post type” of a post:
    •    get_post_type() allows you to check the post type of a
         specific post
$post_type = get_post_type($post_id);




•    Check if a post is of a specific type:
Other Custom Post Type Functions
• Get the “post type” of a post:
    •    get_post_type() allows you to check the post type of a
         specific post
$post_type = get_post_type($post_id);




•      Check if a post is of a specific type:

   •    is_post_type() allows you to check a specific post against
        a specific post type
Other Custom Post Type Functions
• Get the “post type” of a post:
    •    get_post_type() allows you to check the post type of a
         specific post
$post_type = get_post_type($post_id);




•      Check if a post is of a specific type:

   •    is_post_type() allows you to check a specific post against
        a specific post type
if ( is_post_type( 'recipe', $post_id ) )
Other Custom Post Type Functions
• Get the “post type” of a post:
    •    get_post_type() allows you to check the post type of a
         specific post
$post_type = get_post_type($post_id);




•      Check if a post is of a specific type:

   •    is_post_type() allows you to check a specific post against
        a specific post type
if ( is_post_type( 'recipe', $post_id ) )

   echo 'This is a not a blog post. It is a recipe.';
Other Custom Post Type Functions
• Get the “post type” of a post:
    •    get_post_type() allows you to check the post type of a
         specific post
$post_type = get_post_type($post_id);




•      Check if a post is of a specific type:

   •    is_post_type() allows you to check a specific post against
        a specific post type
if ( is_post_type( 'recipe', $post_id ) )

   echo 'This is a not a blog post. It is a recipe.';
else
Other Custom Post Type Functions
• Get the “post type” of a post:
    •    get_post_type() allows you to check the post type of a
         specific post
$post_type = get_post_type($post_id);




•      Check if a post is of a specific type:

   •    is_post_type() allows you to check a specific post against
        a specific post type
if ( is_post_type( 'recipe', $post_id ) )

   echo 'This is a not a blog post. It is a recipe.';
else

   echo 'This is not a recipe.';
Resources
•   WordPress.org Codex: register_post_type function reference:

    •   http://codex.wordpress.org/Function_Reference/register_post_type

•   Blog post: Custom post types in WordPress:

    •   http://justintadlock.com/archives/2010/04/29/custom-post-types-in-
        wordpress

•   Blog post: First impressions of custom post type:

    •   http://wpengineer.com/impressions-of-custom-post-type/

•   Plugin: Custom post type UI plugin for WordPress

    •   http://www.strangework.com/2010/03/03/custom-post-type-ui-plugin-for-
        wordpress/

More Related Content

KEY
Wordcamp St. Louis - Clean Coding
PDF
Custom Post Types in the wild (WordCamp Sofia 2012)
PPTX
Custom Post Types and Taxonomies
KEY
Custom post types - WordPress
PPT
An Introduction to Custom Post Types
PDF
Web Safe Fonts are Dead Series | Part 1: Web Typography Reincarnated
KEY
WordPress as a CMS (short version)
PDF
Add Custom Post Types to Your WordPress Website
Wordcamp St. Louis - Clean Coding
Custom Post Types in the wild (WordCamp Sofia 2012)
Custom Post Types and Taxonomies
Custom post types - WordPress
An Introduction to Custom Post Types
Web Safe Fonts are Dead Series | Part 1: Web Typography Reincarnated
WordPress as a CMS (short version)
Add Custom Post Types to Your WordPress Website

Viewers also liked (9)

PPSX
Workshop 4: IJssel-Vechtdelta lessons learned
KEY
Custom Post Types in Depth at WordCamp Montreal
PDF
Step by step guide for creating wordpress plugin
PPTX
Anatomy and Architecture of a WordPress Theme
PPTX
Architecture for WordPress on AWS
PDF
WordPress Code Architecture
PDF
WordCamp Ireland - 40 tips for WordPress Optimization
ODP
Beginning WordPress Plugin Development
PDF
Wordpress Plugin Development Short Tutorial
Workshop 4: IJssel-Vechtdelta lessons learned
Custom Post Types in Depth at WordCamp Montreal
Step by step guide for creating wordpress plugin
Anatomy and Architecture of a WordPress Theme
Architecture for WordPress on AWS
WordPress Code Architecture
WordCamp Ireland - 40 tips for WordPress Optimization
Beginning WordPress Plugin Development
Wordpress Plugin Development Short Tutorial
Ad

Similar to WordPress 3 Custom Post Types (20)

PPTX
WP 101 - Custom Fields & Post Types
PPTX
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
PDF
Stepping Into Custom Post Types
PDF
WordPress custom posts types for structured content
PPTX
The 3Cs of WordPress
PDF
WordPress Custom Post Types
PPTX
The WordPress University 2012
KEY
WordPress can do that?!
KEY
Theme Development from the Coding End
KEY
Dev Theming
PDF
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...
PDF
Using Custom Post Types and Advanced Custom Fields with Elementor
PPTX
Wordpress Custom Post Types
PDF
WordPress Custom Post Types
KEY
Open Source CMS Playroom
PPTX
PPTX
Wordpress custom-posttype
KEY
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
PPTX
Understanding the ins and outs of word press metadata
PPTX
How to get your theme in WordPress
WP 101 - Custom Fields & Post Types
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
Stepping Into Custom Post Types
WordPress custom posts types for structured content
The 3Cs of WordPress
WordPress Custom Post Types
The WordPress University 2012
WordPress can do that?!
Theme Development from the Coding End
Dev Theming
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...
Using Custom Post Types and Advanced Custom Fields with Elementor
Wordpress Custom Post Types
WordPress Custom Post Types
Open Source CMS Playroom
Wordpress custom-posttype
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
Understanding the ins and outs of word press metadata
How to get your theme in WordPress
Ad

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Modernizing your data center with Dell and AMD
PDF
Encapsulation theory and applications.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
KodekX | Application Modernization Development
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
Teaching material agriculture food technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Modernizing your data center with Dell and AMD
Encapsulation theory and applications.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Approach and Philosophy of On baking technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
Advanced methodologies resolving dimensionality complications for autism neur...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Encapsulation_ Review paper, used for researhc scholars
Unlocking AI with Model Context Protocol (MCP)
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
KodekX | Application Modernization Development
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Teaching material agriculture food technology

WordPress 3 Custom Post Types

  • 1. Custom Post types in WordPress 3 Dave Zille May 15, 2010 - WordCamp Victoria BC
  • 2. About Dave • President, dazil Internet Services • WordPress dev, WordPress conversions • web: dazil.com twitter: @dazil • Principal, Learn it Today • WordPress classroom and online training • web: learnittoday.ca twitter: @learnittodayca
  • 3. Agenda • Custom Post Types: • What are they? What aren’t they? • Why do we need them? • Custom Post Type ideas/examples • Demo: • Creating a custom post type • Displaying a custom post type • Resources
  • 4. WordPress 3: Not just for Blogs Anymore! The term “blog” has been replaced with “site” throughout WordPress 3 is (officially) an actual CMS! WordPress install process now asks for “Site Title”
  • 5. Top 5 Reasons WP is a CMS:
  • 6. Top 5 Reasons WP is a CMS: 1. Scalability
  • 7. Top 5 Reasons WP is a CMS: 1. Scalability 2. Security
  • 8. Top 5 Reasons WP is a CMS: 1. Scalability 2. Security 3. Menu Management
  • 9. Top 5 Reasons WP is a CMS: 1. Scalability 2. Security 3. Menu Management 4. Custom Taxonomies
  • 10. Top 5 Reasons WP is a CMS: 1. Scalability 2. Security 3. Menu Management 4. Custom Taxonomies 5. Custom Post Types
  • 11. What are Custom Post Types? • Custom Post Types are “content” types • Not to be confused with “blog post” • Traditional “post” is actually just another Custom Post Type • Can be used to store and administer different types of content on your WordPress site • Traditionally done via plugins (Flutter, Pods, etc) • A huge part of why WP 3 is a CMS
  • 12. What aren’t Custom Post Types? • Custom Post Types are not: • A replacement for Custom Fields • (used in conjunction with Custom Fields) • Completely GUI driven • (i.e. cannot be created with default WP GUI)
  • 13. Why do we need Custom Post Types? • Because Custom Post Types: • Make it easy to create and edit different forms of content within WordPress • Eliminate the need to “fake” custom post types by using 3rd party plugins • Will make you and your clients happy!
  • 14. Custom Post Type Examples • Media: • Video, Podcasts • Title,YouTube URL, Length/Duration, Captions, Show Notes, etc • Information: • Car for Sale • Make, Model, Color, Features, Pictures, etc..
  • 15. Custom Post Type Examples • Information (cont’d) • Real Estate Listing • Price, # bed, # bath, amenities, photos, etc. • Gallery/Portfolio • Thumbnail, description, URL, etc. • Calendar of Events • Date, time, cost, location, etc.
  • 16. Your First Custom Post Type
  • 17. Your First Custom Post Type • Case Study:
  • 18. Your First Custom Post Type • Case Study: • Recipe database
  • 19. Your First Custom Post Type • Case Study: • Recipe database • Description
  • 20. Your First Custom Post Type • Case Study: • Recipe database • Description • Ingredients
  • 21. Your First Custom Post Type • Case Study: • Recipe database • Description • Ingredients • Prep Time
  • 22. Your First Custom Post Type • Case Study: • Recipe database • Description • Ingredients • Prep Time • Cook Time
  • 23. Custom Post Types: The Code • The register_post_type() function was introduced in WordPress 2.9 • WordPress 3 makes register_post_type() very useful • Minimal code, and a Custom Post Type is up and running: add_action( 'init', 'create_recipe_post_type' ); function create_recipe_post_type() { register_post_type( 'recipe', array( 'label' => __( 'Recipes' ), 'singular_label' => __( 'Recipe' ), 'public' => true, ) ); }
  • 24. Custom Post Types: The Code
  • 25. Custom Post Types: The Code • Where does the code go? • 2 options: • Create a plugin file, or • add to your theme’s functions.php
  • 26. Custom Post Types: The Code • Where does the code go? • 2 options: • Create a plugin file, or • add to your theme’s functions.php • This is useful, but can I do more? • The register_post_type() function has 20+ arguments • Can control a lot about CP Types using them • Let’s review some of them..
  • 27. Custom Post Types: The Code
  • 28. Custom Post Types: The Code register_post_type() arguments • label • A plural descriptive name for the post type • eg “Recipes” • singular_label • A singular descriptive name for the post type • eg “Recipe”
  • 29. Custom Post Types: The Code
  • 30. Custom Post Types: The Code register_post_type() arguments • description • A short descriptive summary of what the post type is • eg. “A set of directions with a list of ingredients for making or preparing food.” • public • Whether or not the post type should be made available in the admin • boolean, default: false
  • 31. Custom Post Types: The Code
  • 32. Custom Post Types: The Code register_post_type() arguments • menu_position • Allows the positioning of the post type in the admin menu • Default: a new post type is added after Comments • menu_icon • Allows you to specify a custom icon for the post type • Default: posts icon
  • 33. Custom Post Types: The Code
  • 34. Custom Post Types: The Code register_post_type() arguments
  • 35. Custom Post Types: The Code register_post_type() arguments • hierarchical
  • 36. Custom Post Types: The Code register_post_type() arguments • hierarchical • Determines whether the post type is hierarchical (as in ‘pages’), or not (as in ‘posts’)
  • 37. Custom Post Types: The Code register_post_type() arguments • hierarchical • Determines whether the post type is hierarchical (as in ‘pages’), or not (as in ‘posts’) • Default: false
  • 38. Custom Post Types: The Code register_post_type() arguments • hierarchical • Determines whether the post type is hierarchical (as in ‘pages’), or not (as in ‘posts’) • Default: false • can_export
  • 39. Custom Post Types: The Code register_post_type() arguments • hierarchical • Determines whether the post type is hierarchical (as in ‘pages’), or not (as in ‘posts’) • Default: false • can_export • Specifies whether posts of the post type can be exportable using WordPress’ export function
  • 40. Custom Post Types: The Code register_post_type() arguments • hierarchical • Determines whether the post type is hierarchical (as in ‘pages’), or not (as in ‘posts’) • Default: false • can_export • Specifies whether posts of the post type can be exportable using WordPress’ export function • Default: true
  • 41. Custom Post Types: The Code
  • 42. Custom Post Types: The Code register_post_type() arguments
  • 43. Custom Post Types: The Code register_post_type() arguments • supports
  • 44. Custom Post Types: The Code register_post_type() arguments • supports • Defines what meta boxes and other fields appear when editing or creating a post
  • 45. Custom Post Types: The Code register_post_type() arguments • supports • Defines what meta boxes and other fields appear when editing or creating a post • Options: title, editor, comments, trackbacks, revisions, author, excerpt, thumbnail, custom- fields, page-attributes
  • 46. Custom Post Types: The Code register_post_type() arguments • supports • Defines what meta boxes and other fields appear when editing or creating a post • Options: title, editor, comments, trackbacks, revisions, author, excerpt, thumbnail, custom- fields, page-attributes • Default: title, editor
  • 47. Custom Post Types: The Code
  • 48. Custom Post Types: The Code register_post_type() arguments
  • 49. Custom Post Types: The Code register_post_type() arguments • register_meta_box_cb
  • 50. Custom Post Types: The Code register_post_type() arguments • register_meta_box_cb • taxonomies
  • 51. Custom Post Types: The Code register_post_type() arguments • register_meta_box_cb • taxonomies • capability_type / capabilities
  • 52. Custom Post Types: Displaying
  • 53. Custom Post Types: Displaying • Customizing the custom post type template
  • 54. Custom Post Types: Displaying • Customizing the custom post type template • single.php
  • 55. Custom Post Types: Displaying • Customizing the custom post type template • single.php • template for the custom post type (default)
  • 56. Custom Post Types: Displaying • Customizing the custom post type template • single.php • template for the custom post type (default) • single-post_type_name.php
  • 57. Custom Post Types: Displaying • Customizing the custom post type template • single.php • template for the custom post type (default) • single-post_type_name.php • custom template for the custom post type
  • 58. Custom Post Types: Displaying • Customizing the custom post type template • single.php • template for the custom post type (default) • single-post_type_name.php • custom template for the custom post type • eg. single-recipe.php
  • 59. Custom Post Types: Displaying
  • 60. Custom Post Types: Displaying • Displaying custom post types on your site’s homepage
  • 61. Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php:
  • 62. Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' );
  • 63. Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) {
  • 64. Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() )
  • 65. Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() ) $query->set( 'post_type', array( 'post', 'recipe' ) );
  • 66. Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() ) $query->set( 'post_type', array( 'post', 'recipe' ) ); return $query;
  • 67. Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() ) $query->set( 'post_type', array( 'post', 'recipe' ) ); return $query; }
  • 68. Other Custom Post Type Functions
  • 69. Other Custom Post Type Functions • Get the “post type” of a post:
  • 70. Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post
  • 71. Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id);
  • 72. Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type:
  • 73. Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type: • is_post_type() allows you to check a specific post against a specific post type
  • 74. Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type: • is_post_type() allows you to check a specific post against a specific post type if ( is_post_type( 'recipe', $post_id ) )
  • 75. Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type: • is_post_type() allows you to check a specific post against a specific post type if ( is_post_type( 'recipe', $post_id ) ) echo 'This is a not a blog post. It is a recipe.';
  • 76. Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type: • is_post_type() allows you to check a specific post against a specific post type if ( is_post_type( 'recipe', $post_id ) ) echo 'This is a not a blog post. It is a recipe.'; else
  • 77. Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type: • is_post_type() allows you to check a specific post against a specific post type if ( is_post_type( 'recipe', $post_id ) ) echo 'This is a not a blog post. It is a recipe.'; else echo 'This is not a recipe.';
  • 78. Resources • WordPress.org Codex: register_post_type function reference: • http://codex.wordpress.org/Function_Reference/register_post_type • Blog post: Custom post types in WordPress: • http://justintadlock.com/archives/2010/04/29/custom-post-types-in- wordpress • Blog post: First impressions of custom post type: • http://wpengineer.com/impressions-of-custom-post-type/ • Plugin: Custom post type UI plugin for WordPress • http://www.strangework.com/2010/03/03/custom-post-type-ui-plugin-for- wordpress/