SlideShare a Scribd company logo
1 of 28
1




          Custom Post Types
                 Now What?
                           By Cody Helgeson
                      WordCamp Phoenix 2012




    @codyhelgeson | @fallingupmedia | #wcphx
2




    Find More Info

     Who Am I?
     My Experience with WordPress

     @codyhelgeson
     @fallingupmedia
     fallingupmedia.com
     cody@fallingupmedia.com




           @codyhelgeson | @fallingupmedia | #wcphx
3




    Topics For The Day
     • Custom Post Type Best Practices
     • Custom Taxonomies
     • Page Templates
     • Custom Fields
     • Custom Admin Columns
     • Custom Queries




           @codyhelgeson | @fallingupmedia | #wcphx
4




    Custom Post Types

     • Who has or is about to use custom post types?
     • Why use custom post types
     • Why not?
     • For the client
     • For the developer




            @codyhelgeson | @fallingupmedia | #wcphx
5




    Custom Post Types
    Examples

     • Book and Product Reviews
     • Job and Business Listings
     • Events and Locations
     • Portfolios and Case Studies
     • Combine with BuddyPress for Community Domination!
     • Anything your Heart Desires....



            @codyhelgeson | @fallingupmedia | #wcphx
6




     Custom Post Types
     The Code

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

        • Contextual help menus are a nice touch
        • Permalinks matter!
        • Flush the rewrite rules, or save permalink settings
        • /%category%/%postname%/
        • www.domain.com/custom-post-type/post-title



               @codyhelgeson | @fallingupmedia | #wcphx
7




    Topics For The Day

     • Custom Post Type Best Practices
     • Custom Taxonomies
     • Page Templates
     • Custom Fields
     • Custom Admin Columns
     • Custom Queries



           @codyhelgeson | @fallingupmedia | #wcphx
8




    Custom Taxonomies

             http://codex.wordpress.org/Taxonomies


     • Categorizes and groups content
     • Hierarchal or not? I.E. tags or categories
     • Clean and intuitive for users
     • Custom slugs argument
     • Create custom page templates and queries


            @codyhelgeson | @fallingupmedia | #wcphx
9




     Custom Taxonomies
     The Code

    http://codex.wordpress.org/Function_Reference/register_taxonomy

        • Flush rewrite or save permalink settings
        • There are reserved terms!
        • register_taxonomy($taxonomy, $object_type, $args); 




               @codyhelgeson | @fallingupmedia | #wcphx
10




     Topics For The Day
     Custom Post Types

       • Custom Post Type Best Practices
       • Custom Taxonomies
       • Page Templates
       • Custom Fields
       • Custom Admin Columns
       • Custom Queries



             @codyhelgeson | @fallingupmedia | #wcphx
11




     Page Templates
          http://codex.wordpress.org/Template_Hierarchy


      • WordPress makes it easy! Use them!
      • single-post_type.php
      • archive-post_type.php
      • taxonomy-taxonomy_name-slug.php
      • taxonomy-taxonomy_name.php


            @codyhelgeson | @fallingupmedia | #wcphx
12




     Topics For The Day
     Custom Post Types

       • Custom Post Type Best Practices
       • Custom Taxonomies
       • Page Templates
       • Custom Fields
       • Custom Admin Columns
       • Custom Queries



             @codyhelgeson | @fallingupmedia | #wcphx
13




     Custom Fields
             http://codex.wordpress.org/Custom_Fields


      • Purely incredible! Endless possibilities
      • Remove what you don’t need from editor. Take the time
      • Create your own or use a plugin
        • Advanced Custom Fields plugin
        • Magic Fields plugin
      • get_post_meta - add_post_meta

             @codyhelgeson | @fallingupmedia | #wcphx
14




     Custom Fields
     Examples



        • Real world examples on the web......




            @codyhelgeson | @fallingupmedia | #wcphx
15




     Topics For The Day
     Custom Post Types

       • Custom Post Type Best Practices
       • Custom Taxonomies
       • Page Templates
       • Custom Fields
       • Custom Admin Columns
       • Custom Queries



             @codyhelgeson | @fallingupmedia | #wcphx
16




     Custom Admin Columns
     The Code

 http://codex.wordpress.org/Plugin_API/Action_Reference/
 manage_posts_custom_column

 http://codex.wordpress.org/Plugin_API/Filter_Reference/
 manage_edit-post_type_columns


 add_action("manage_posts_custom_column", "your_custom_post_column_function");

 add_filter("manage_edit-$post_type_columns", "your_custom_column_function");




               @codyhelgeson | @fallingupmedia | #wcphx
17



 http://blog.elliotcondon.com/wordpress/advanced-custom-fields-
 admin-custom-columns/


     function my_page_columns($columns)
     {
     " $columns = array(
     " " 'cb'" " => '<input type="checkbox" />',
     " " 'thumbnail'" =>"'Thumbnail',
     " " 'title' " => 'Title',
     " " 'featured' "=> 'Featured',
     " " 'author'" =>"'Author',
     " " 'date'" " =>"'Date',
     " );
     " return $columns;
     }




                 @codyhelgeson | @fallingupmedia | #wcphx
18


     function my_custom_columns($column)
     {
     " global $post;
     " if($column == 'thumbnail')
     " {
     " " echo wp_get_attachment_image( get_field('page_image', $post->ID), array(200,200) );
     " }
     " elseif($column == 'featured')
     " {
     " " if(get_field('featured'))
     " " {
     " " " echo 'Yes';
     " " }
     " " else
     " " {
     " " " echo 'No';
     " " }
     " }
     }
      
     add_action("manage_pages_custom_column", "my_custom_columns");
     add_filter("manage_edit-page_columns", "my_page_columns");



                    @codyhelgeson | @fallingupmedia | #wcphx
19




     Custom Admin Columns
     Examples




           @codyhelgeson | @fallingupmedia | #wcphx
20




 http://www.trymypoolguy.com

     function my_post_columns_forums($columns)
     {
     " $columns = array(
     " " 'cb'" " => '<input type="checkbox" />',
     " " 'title' " => 'Listing Title',
     " " 'featured'" => 'Featured',
     " " 'author'      => 'Author',
     " " 'comments' => '<img src="image_path_goes_here" />',
     " " 'zips'     => 'Zip Code',
     " " 'services'       => 'Services',
     " " 'repairs'      => 'Repairs',
     " " 'date'" " => 'Date',
     " );
     " return $columns;
     }




                @codyhelgeson | @fallingupmedia | #wcphx
21
     function my_custom_columns_forums($column)
     {
     "   global $post;
     "   if($column == 'featured')
     "   {
     "   "     if(get_field('featured'))
     "   "     {
     "   "     "    echo '<strong>Yes</strong>';
     "   "     }
     "   "     else
     "   "     {
     "   "     "    echo '';
     "   "     }
     "   }
     "   if($column == 'zips')
     "   {
     "   "     echo get_field('zip_code', $post->ID);
     "   }
     "   if($column == 'services')
     "   {
     "     $custom_fields = get_post_custom($post->ID);
     "     $my_custom_field = $custom_fields['services'];
     "     foreach ( $my_custom_field as $key => $value )
     "       echo $value . "<br />";
     "   }
     "   if($column == 'repairs')
     "   {
     "     $custom_fields = get_post_custom($post->ID);
     "     $my_custom_field = $custom_fields['repairs'];
     "     foreach ( $my_custom_field as $key => $value )
     "       echo $value . "<br />";
     "   }
22




     Custom Admin Columns
     Examples




           @codyhelgeson | @fallingupmedia | #wcphx
23




     Topics For The Day
     Custom Post Types

       • Custom Post Type Best Practices
       • Custom Taxonomies
       • Page Templates
       • Custom Fields
       • Custom Admin Columns
       • Custom Queries



             @codyhelgeson | @fallingupmedia | #wcphx
24




     Custom Queries
       http://codex.wordpress.org/Template_Tags/get_posts
      http://codex.wordpress.org/Class_Reference/WP_Query


      • get_posts
        • does not modify global variables
      • wp_query
        • always <?php wp_reset_query(); ?>




            @codyhelgeson | @fallingupmedia | #wcphx
25




     Custom Queries
     get posts from:
     custom post type - dogfood
     and category = brand
      <?php
      $args = array(
         'numberposts' => 8,
         'orderby' => 'rand',
         'post_type' => 'dogfood',
         'dogfood_category' => 'brand',
         'post_status' => 'publish'
      );
      $show_brands = get_posts ( $args );
      ?>




                  @codyhelgeson | @fallingupmedia | #wcphx
26




     Custom Queries
     Examples



        • Real world examples on the web......




            @codyhelgeson | @fallingupmedia | #wcphx
27




     Thank You!

      @codyhelgeson
      @fallingupmedia
      fallingupmedia.com
      cody@fallingupmedia.com




            @codyhelgeson | @fallingupmedia | #wcphx
28




           Custom Post Types
                  Now What?
                            By Cody Helgeson
                       WordCamp Phoenix 2012




     @codyhelgeson | @fallingupmedia | #wcphx

More Related Content

What's hot

Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGent
kevinvw
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheets
chriseppstein
 

What's hot (12)

Intro to Ruby on Rails
Intro to Ruby on RailsIntro to Ruby on Rails
Intro to Ruby on Rails
 
Lose Your Head! Re-imagining WordPress's Role in Content Presentation
Lose Your Head! Re-imagining WordPress's Role in Content PresentationLose Your Head! Re-imagining WordPress's Role in Content Presentation
Lose Your Head! Re-imagining WordPress's Role in Content Presentation
 
Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGent
 
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
 
The Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web DevelopmentThe Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web Development
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheets
 
HTML5: Introduction
HTML5: IntroductionHTML5: Introduction
HTML5: Introduction
 
Jquery News Packages
Jquery News PackagesJquery News Packages
Jquery News Packages
 
Styling Components with JavaScript: MelbCSS Edition
Styling Components with JavaScript: MelbCSS EditionStyling Components with JavaScript: MelbCSS Edition
Styling Components with JavaScript: MelbCSS Edition
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScript
 
WAI-ARIA is More Than Accessibility
WAI-ARIA is More Than AccessibilityWAI-ARIA is More Than Accessibility
WAI-ARIA is More Than Accessibility
 
Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developer
 

Similar to Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson

Wordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean CodingWordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean Coding
inspector_fegter
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
Stephanie Leary
 

Similar to Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson (20)

WordPress 3 Custom Post Types
WordPress 3 Custom Post TypesWordPress 3 Custom Post Types
WordPress 3 Custom Post Types
 
Wordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean CodingWordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean Coding
 
WordPress: A Designer's CMS
WordPress: A Designer's CMSWordPress: A Designer's CMS
WordPress: A Designer's CMS
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
 
Theme Development from the Coding End
Theme Development from the Coding EndTheme Development from the Coding End
Theme Development from the Coding End
 
Dev Theming
Dev ThemingDev Theming
Dev Theming
 
Cain & Obenland — Episode 4
Cain & Obenland — Episode 4Cain & Obenland — Episode 4
Cain & Obenland — Episode 4
 
Wordpress beyond blogging
Wordpress beyond bloggingWordpress beyond blogging
Wordpress beyond blogging
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
Carrington Core (2014)
Carrington Core (2014)Carrington Core (2014)
Carrington Core (2014)
 
Simple Usability Tweaks for Your WordPress Theme
Simple Usability Tweaks for Your WordPress ThemeSimple Usability Tweaks for Your WordPress Theme
Simple Usability Tweaks for Your WordPress Theme
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)
 
WordPress 3.4 Theme Customizer
WordPress 3.4 Theme CustomizerWordPress 3.4 Theme Customizer
WordPress 3.4 Theme Customizer
 
What's New in WordPress 3.0 (for developers)
What's New in WordPress 3.0 (for developers)What's New in WordPress 3.0 (for developers)
What's New in WordPress 3.0 (for developers)
 
Custom Fields & Custom Metaboxes Overview
Custom Fields & Custom Metaboxes OverviewCustom Fields & Custom Metaboxes Overview
Custom Fields & Custom Metaboxes Overview
 
WP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post TypesWP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post Types
 
Beyond Posts and Pages: Structured Content in WordPress
Beyond Posts and Pages: Structured Content in WordPressBeyond Posts and Pages: Structured Content in WordPress
Beyond Posts and Pages: Structured Content in WordPress
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/2016Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/2016
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson

  • 1. 1 Custom Post Types Now What? By Cody Helgeson WordCamp Phoenix 2012 @codyhelgeson | @fallingupmedia | #wcphx
  • 2. 2 Find More Info Who Am I? My Experience with WordPress @codyhelgeson @fallingupmedia fallingupmedia.com cody@fallingupmedia.com @codyhelgeson | @fallingupmedia | #wcphx
  • 3. 3 Topics For The Day • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 4. 4 Custom Post Types • Who has or is about to use custom post types? • Why use custom post types • Why not? • For the client • For the developer @codyhelgeson | @fallingupmedia | #wcphx
  • 5. 5 Custom Post Types Examples • Book and Product Reviews • Job and Business Listings • Events and Locations • Portfolios and Case Studies • Combine with BuddyPress for Community Domination! • Anything your Heart Desires.... @codyhelgeson | @fallingupmedia | #wcphx
  • 6. 6 Custom Post Types The Code http://codex.wordpress.org/Function_Reference/register_post_type • Contextual help menus are a nice touch • Permalinks matter! • Flush the rewrite rules, or save permalink settings • /%category%/%postname%/ • www.domain.com/custom-post-type/post-title @codyhelgeson | @fallingupmedia | #wcphx
  • 7. 7 Topics For The Day • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 8. 8 Custom Taxonomies http://codex.wordpress.org/Taxonomies • Categorizes and groups content • Hierarchal or not? I.E. tags or categories • Clean and intuitive for users • Custom slugs argument • Create custom page templates and queries @codyhelgeson | @fallingupmedia | #wcphx
  • 9. 9 Custom Taxonomies The Code http://codex.wordpress.org/Function_Reference/register_taxonomy • Flush rewrite or save permalink settings • There are reserved terms! • register_taxonomy($taxonomy, $object_type, $args);  @codyhelgeson | @fallingupmedia | #wcphx
  • 10. 10 Topics For The Day Custom Post Types • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 11. 11 Page Templates http://codex.wordpress.org/Template_Hierarchy • WordPress makes it easy! Use them! • single-post_type.php • archive-post_type.php • taxonomy-taxonomy_name-slug.php • taxonomy-taxonomy_name.php @codyhelgeson | @fallingupmedia | #wcphx
  • 12. 12 Topics For The Day Custom Post Types • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 13. 13 Custom Fields http://codex.wordpress.org/Custom_Fields • Purely incredible! Endless possibilities • Remove what you don’t need from editor. Take the time • Create your own or use a plugin • Advanced Custom Fields plugin • Magic Fields plugin • get_post_meta - add_post_meta @codyhelgeson | @fallingupmedia | #wcphx
  • 14. 14 Custom Fields Examples • Real world examples on the web...... @codyhelgeson | @fallingupmedia | #wcphx
  • 15. 15 Topics For The Day Custom Post Types • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 16. 16 Custom Admin Columns The Code http://codex.wordpress.org/Plugin_API/Action_Reference/ manage_posts_custom_column http://codex.wordpress.org/Plugin_API/Filter_Reference/ manage_edit-post_type_columns add_action("manage_posts_custom_column", "your_custom_post_column_function"); add_filter("manage_edit-$post_type_columns", "your_custom_column_function"); @codyhelgeson | @fallingupmedia | #wcphx
  • 17. 17 http://blog.elliotcondon.com/wordpress/advanced-custom-fields- admin-custom-columns/ function my_page_columns($columns) { " $columns = array( " " 'cb'" " => '<input type="checkbox" />', " " 'thumbnail'" =>"'Thumbnail', " " 'title' " => 'Title', " " 'featured' "=> 'Featured', " " 'author'" =>"'Author', " " 'date'" " =>"'Date', " ); " return $columns; } @codyhelgeson | @fallingupmedia | #wcphx
  • 18. 18 function my_custom_columns($column) { " global $post; " if($column == 'thumbnail') " { " " echo wp_get_attachment_image( get_field('page_image', $post->ID), array(200,200) ); " } " elseif($column == 'featured') " { " " if(get_field('featured')) " " { " " " echo 'Yes'; " " } " " else " " { " " " echo 'No'; " " } " } }   add_action("manage_pages_custom_column", "my_custom_columns"); add_filter("manage_edit-page_columns", "my_page_columns"); @codyhelgeson | @fallingupmedia | #wcphx
  • 19. 19 Custom Admin Columns Examples @codyhelgeson | @fallingupmedia | #wcphx
  • 20. 20 http://www.trymypoolguy.com function my_post_columns_forums($columns) { " $columns = array( " " 'cb'" " => '<input type="checkbox" />', " " 'title' " => 'Listing Title', " " 'featured'" => 'Featured', " " 'author' => 'Author', " " 'comments' => '<img src="image_path_goes_here" />', " " 'zips' => 'Zip Code', " " 'services' => 'Services', " " 'repairs' => 'Repairs', " " 'date'" " => 'Date', " ); " return $columns; } @codyhelgeson | @fallingupmedia | #wcphx
  • 21. 21 function my_custom_columns_forums($column) { " global $post; " if($column == 'featured') " { " " if(get_field('featured')) " " { " " " echo '<strong>Yes</strong>'; " " } " " else " " { " " " echo ''; " " } " } " if($column == 'zips') " { " " echo get_field('zip_code', $post->ID); " } " if($column == 'services') " { " $custom_fields = get_post_custom($post->ID); " $my_custom_field = $custom_fields['services']; " foreach ( $my_custom_field as $key => $value ) " echo $value . "<br />"; " } " if($column == 'repairs') " { " $custom_fields = get_post_custom($post->ID); " $my_custom_field = $custom_fields['repairs']; " foreach ( $my_custom_field as $key => $value ) " echo $value . "<br />"; " }
  • 22. 22 Custom Admin Columns Examples @codyhelgeson | @fallingupmedia | #wcphx
  • 23. 23 Topics For The Day Custom Post Types • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 24. 24 Custom Queries http://codex.wordpress.org/Template_Tags/get_posts http://codex.wordpress.org/Class_Reference/WP_Query • get_posts • does not modify global variables • wp_query • always <?php wp_reset_query(); ?> @codyhelgeson | @fallingupmedia | #wcphx
  • 25. 25 Custom Queries get posts from: custom post type - dogfood and category = brand <?php $args = array( 'numberposts' => 8, 'orderby' => 'rand', 'post_type' => 'dogfood', 'dogfood_category' => 'brand', 'post_status' => 'publish' ); $show_brands = get_posts ( $args ); ?> @codyhelgeson | @fallingupmedia | #wcphx
  • 26. 26 Custom Queries Examples • Real world examples on the web...... @codyhelgeson | @fallingupmedia | #wcphx
  • 27. 27 Thank You! @codyhelgeson @fallingupmedia fallingupmedia.com cody@fallingupmedia.com @codyhelgeson | @fallingupmedia | #wcphx
  • 28. 28 Custom Post Types Now What? By Cody Helgeson WordCamp Phoenix 2012 @codyhelgeson | @fallingupmedia | #wcphx

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n