Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Custom post-types & taxonomies

Slides from a talk on custom post types and taxonomies in Wordpress from a backend developers perspective.

  • Be the first to comment

Custom post-types & taxonomies

  1. 1. CUSTOM POST TYPES & TAXONOMIES Christopher Reding - @creding - April 18th 2011
  2. 2. What?Posts in Wordpress are stored in the wp_posts table. Within this table there is acolumn for the post type. Using this column Wordpress can determine the correctform of presentation or relationship the post requires when querying for that posttype.Custom Post Types are no different, they too are stored in the wp_posts table andhave all the characteristics of their sibling objects. The only real difference is youdefine them. The name, attributes, and abilities can be customized allowing you toexpand the possibilities of Wordpress beyond what many ever thought possiblewithout a plugin.
  3. 3. What?Taxonomies are the categories and tags we all know and love. They enable posts tobe divided and subdivided into relational containers making it a breeze to navigateas well as see related topics.Custom taxonomies are no different, they can do all the same things. The onlydifference is that you are in control of what that taxonomy is applied to and how itcan be used - just like custom post types.
  4. 4. Creating Your Custom Post TypeBeer $labels = array( name => _x(Beer, post type general name),Define Labels singular_name => _x(Beer, post type singular name), add_new => _x(Add New, beer), add_new_item => __(Add New Beer), edit_item => __(Edit Beer), new_item => __(New Beer), view_item => __(View Beer), search_items => __(Search For Beers), not_found => __(No beers found), not_found_in_trash => __(No beers found in Trash), parent_item_colon => , menu_name => Beers );
  5. 5. Creating Your Custom Post TypeBeer $args = array( labels => $labels, public => true, publicly_queryable => true, show_ui => true,Define Attributes show_in_menu => true, query_var => true, rewrite => true, capability_type => post, has_archive => true, hierarchical => false, menu_position => 10, supports => array(title,editor,author,thumbnail,excerpt,comments) );Register It register_post_type(beer,$args);
  7. 7. Custom Meta BoxesNow that you have a custom post type you may want to define some extra fields.Using a custom meta box you can create a form containing the fields you want touse. You then use that form to populate the post’s meta data. The wp_postmetatable in the database enables us to relate data to the post and give it a key name(meta_key => meta_value)This is made even easier using the WPAlchemy MetaBox PHP class
  8. 8. EVENT META BOXAdds a form to the event custom post type allowing specific event data to be stored.
  9. 9. AND THE FRONT END Event custom post type displayed from the front end.
  10. 10. Why?Pre-formatted content such as an event.To isolate content into silos making it easier on the content creators.Save the WP database from the ravage of excessive table bloat.A better integration for plugin creators who want to take advantage of built-in WPfunctions such as search, archives, and permalinks.
  11. 11. QUESTIONS? @creding