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

Viewers also liked

Workshop 4: IJssel-Vechtdelta lessons learned
Workshop 4: IJssel-Vechtdelta lessons learnedWorkshop 4: IJssel-Vechtdelta lessons learned
Workshop 4: IJssel-Vechtdelta lessons learned
Bas van Dishoeck
 
Custom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp MontrealCustom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp Montreal
Joey Kudish
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginMainak Goswami
 
Anatomy and Architecture of a WordPress Theme
Anatomy and Architecture of a WordPress ThemeAnatomy and Architecture of a WordPress Theme
Anatomy and Architecture of a WordPress ThemeJulie Kuehl
 
WordPress Code Architecture
WordPress Code ArchitectureWordPress Code Architecture
WordPress Code Architecture
Mario Peshev
 
WordCamp Ireland - 40 tips for WordPress Optimization
WordCamp Ireland - 40 tips for WordPress OptimizationWordCamp Ireland - 40 tips for WordPress Optimization
WordCamp Ireland - 40 tips for WordPress Optimization
Joost de Valk
 
Beginning WordPress Plugin Development
Beginning WordPress Plugin DevelopmentBeginning WordPress Plugin Development
Beginning WordPress Plugin Development
Aizat Faiz
 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short Tutorial
Christos Zigkolis
 

Viewers also liked (9)

Workshop 4: IJssel-Vechtdelta lessons learned
Workshop 4: IJssel-Vechtdelta lessons learnedWorkshop 4: IJssel-Vechtdelta lessons learned
Workshop 4: IJssel-Vechtdelta lessons learned
 
Custom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp MontrealCustom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp Montreal
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
 
Anatomy and Architecture of a WordPress Theme
Anatomy and Architecture of a WordPress ThemeAnatomy and Architecture of a WordPress Theme
Anatomy and Architecture of a WordPress Theme
 
Architecture for WordPress on AWS
Architecture for WordPress on AWSArchitecture for WordPress on AWS
Architecture for WordPress on AWS
 
WordPress Code Architecture
WordPress Code ArchitectureWordPress Code Architecture
WordPress Code Architecture
 
WordCamp Ireland - 40 tips for WordPress Optimization
WordCamp Ireland - 40 tips for WordPress OptimizationWordCamp Ireland - 40 tips for WordPress Optimization
WordCamp Ireland - 40 tips for WordPress Optimization
 
Beginning WordPress Plugin Development
Beginning WordPress Plugin DevelopmentBeginning WordPress Plugin Development
Beginning WordPress Plugin Development
 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short Tutorial
 

Similar to WordPress 3 Custom Post Types

WP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post TypesWP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post Types
Joe Querin
 
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom FieldsWordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
Joe Querin
 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post TypesK.Adam White
 
WordPress custom posts types for structured content
WordPress custom posts types for structured contentWordPress custom posts types for structured content
WordPress custom posts types for structured content
Firestorm Creative Studios
 
The 3Cs of WordPress
The 3Cs of WordPressThe 3Cs of WordPress
The 3Cs of WordPress
David Tufts
 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post TypesMark Jaquith
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012Stephanie Leary
 
WordPress can do that?!
WordPress can do that?!WordPress can do that?!
WordPress can do that?!
Scott McNulty
 
Theme Development from the Coding End
Theme Development from the Coding EndTheme Development from the Coding End
Theme Development from the Coding End
East Bay WordPress Meetup
 
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...
Evan Mullins
 
Using Custom Post Types and Advanced Custom Fields with Elementor
 Using Custom Post Types and Advanced Custom Fields with Elementor Using Custom Post Types and Advanced Custom Fields with Elementor
Using Custom Post Types and Advanced Custom Fields with Elementor
Angela Bowman
 
Wordpress Custom Post Types
Wordpress Custom Post TypesWordpress Custom Post Types
Wordpress Custom Post Types
Brent Williams
 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post Types
Nile Flores
 
Open Source CMS Playroom
Open Source CMS PlayroomOpen Source CMS Playroom
Open Source CMS Playroomlibrarywebchic
 
TypeScript
TypeScriptTypeScript
Wordpress custom-posttype
Wordpress custom-posttypeWordpress custom-posttype
Wordpress custom-posttypeNaeem Junejo
 
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody HelgesonWordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
Cody Helgeson
 
Understanding the ins and outs of word press metadata
Understanding the ins and outs of word press metadataUnderstanding the ins and outs of word press metadata
Understanding the ins and outs of word press metadata
Nicholas Batik
 
How to get your theme in WordPress
How to get your theme in WordPressHow to get your theme in WordPress
How to get your theme in WordPressNisha Singh
 

Similar to WordPress 3 Custom Post Types (20)

WP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post TypesWP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post Types
 
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom FieldsWordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post Types
 
WordPress custom posts types for structured content
WordPress custom posts types for structured contentWordPress custom posts types for structured content
WordPress custom posts types for structured content
 
The 3Cs of WordPress
The 3Cs of WordPressThe 3Cs of WordPress
The 3Cs of WordPress
 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post Types
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
 
WordPress can do that?!
WordPress can do that?!WordPress can do that?!
WordPress can do that?!
 
Dev Theming
Dev ThemingDev Theming
Dev Theming
 
Theme Development from the Coding End
Theme Development from the Coding EndTheme Development from the Coding End
Theme Development from the Coding End
 
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...
 
Using Custom Post Types and Advanced Custom Fields with Elementor
 Using Custom Post Types and Advanced Custom Fields with Elementor Using Custom Post Types and Advanced Custom Fields with Elementor
Using Custom Post Types and Advanced Custom Fields with Elementor
 
Wordpress Custom Post Types
Wordpress Custom Post TypesWordpress Custom Post Types
Wordpress Custom Post Types
 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post Types
 
Open Source CMS Playroom
Open Source CMS PlayroomOpen Source CMS Playroom
Open Source CMS Playroom
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Wordpress custom-posttype
Wordpress custom-posttypeWordpress custom-posttype
Wordpress custom-posttype
 
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody HelgesonWordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
 
Understanding the ins and outs of word press metadata
Understanding the ins and outs of word press metadataUnderstanding the ins and outs of word press metadata
Understanding the ins and outs of word press metadata
 
How to get your theme in WordPress
How to get your theme in WordPressHow to get your theme in WordPress
How to get your theme in WordPress
 

Recently uploaded

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 

Recently uploaded (20)

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 

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/

Editor's Notes