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 in Depth at WordCamp Montreal

Since WordPress 3.0 added Custom Post Types, WordPress has become a truly powerful and extensible Content Management System for any need. In this talk we’ll review the what, why and how of custom post types. If you’ve been meaning to learn beyond the basics of Custom Post Types, now is the time!

Starting with what CPTs are and how they’re used, we’ll explain how to register/create them as well as how make them most of them in your themes and plugins. We’ll discuss the Custom Post Types API as well as its shortcomings, and consider various UI-based CPT plugins and their pros and cons as well other innovative approaches. Custom Post Types are the future of WordPress, don’t miss out!

Basic knowledge of WordPress coding standards & PHP. HTML/CSS helpful but not required.

About Colin and Joachim
Co-founder of stresslimit, Colin has consulted on, architected and developed CMS platforms, intranets, applications and websites of all shapes & sizes for over a decade. Having watched the WordPress project be born, grow & develop, he now champions the simplicity and extensibility of the world’s most popular blogging (and now CMS) platform. Follow @stresslimit on Twitter.

Joachim created his first website at the age of 11. Ever since, he’s been passionate about all things web and has given himself the technical know-how to develop websites. In 2008, he tried out WordPress, and fell in love with the platform, and is happy to have seen it grow to where it is today. Referred to as the “WordPress guru” in the office, Joachim is now one of the lead developers at stresslimit, as well as a WordPress freelance developer. Follow @jkudish on Twitter.

  • Login to see the comments

Custom Post Types in Depth at WordCamp Montreal

  1. 1. WordPress Custom Post Types In-Depth Colin Vernon & Joachim Kudish
  2. 2. Organizing Content ofDifferent Types• It’s about Content: websites usually have content of different types: posts, pages, articles, videos, newsletters, products, books, anything• A question of content and information architecture vs data structure
  3. 3. Back in the day... • Websites were simpler... ? • Created custom architecture with pages • Different content types could be “faked” with categories and category navigation
  4. 4. What are custom posttypes?• Introduced in WordPress 2.9, much simplified in 3.0 and expanded upon in 3.1• Classic blog format used categories to classify content• Custom post types allow for more in-depth fine-grained control and separation of content• Better name = custom content type
  5. 5. Advanced uses of CPTs• Products (WP E-Commerce uses it -• Job Postings• Testimonials• Newsletters• Possibilities are endless!
  6. 6. Registering Custom PostTypes Graphical/easy way: • Plug and play, simple interfaces • Custom Post Type UI - http:// post-type-ui/ • GD Custom Posts And Taxonomies Tools - gd-taxonomies-tools/ • More Types - extend/plugins/more-types/ • Lots of other examples
  8. 8. Code Method register_post_type(); • Function_Reference/register_post_type • core function • lots of $args for lots of possibilities
  9. 9. (taken from the WP Codex)
  10. 10. $args = customizationAdmin: • labels, show_ui, show_in_menu, menu_position, menu_icon, capability_type, capabilities, map_meta_cap, register_meta_box_cb, can_export, show_in_nav_menusFront-end: • public, publicly_queryable, exclude_from_search, hierarchical, taxonomiesPermalinks:
  11. 11. Code = Good ☺• versionable (svn, git, etc...)• core WordPress way• easy to edit at any time• you keep full control• similar to what GUI plugins do, but without relying on the database• only a few lines of code
  12. 12. Some Shortcomings ofWP API • lots of repetition in the code • not good enough defaults (labels!) • now has good support for archives (since 3.1) but still no built-in support for feed permalinks, etc.
  13. 13. Alternate Code Methods• Smarter Custom Post Types by Matt Wiebe: • custom-post-types/ • now obsolete because of 3.1’s archive/ permalinks abilities• Our own SLD Custom Content & Taxonomy • Custom-Post-Types-Taxonomies-for- Wordpress • wrapper plugin/class for
  14. 14. Taking CPTs evenfurther• Taxonomies • further way of classifying content • group different content types together based on taxonomies • use built-in taxonomies (categories & tags) or custom taxonomies • register custom taxonomies with code, not GUI plugins • use the core WP function register_taxonomy() Function_Reference/register_taxonomy
  15. 15.
  16. 16. Taking CPTs evenfurther• Meta fields / meta boxes / custom fields: • allow you to store any information • extremely expandable • WordPress API requires a lot of code, no good defaults: • add_meta_box() • Function_Reference/add_meta_box
  17. 17. Meta Boxes• similarly to content types & taxonomies, there are GUI plugins to register meta boxes • More Fields: extend/plugins/more-fields/ • Advanced Custom Fields: http:// advanced-custom-fields/ • Verve Meta Boxes: http:// meta-boxes/
  18. 18. Easier Meta Fields • Custom Metadata Manager by Mohammad Jangda • custom-metadata/ • easy wrapper functions for adding meta boxes and custom fields
  19. 19. Custom MetadataManagerx_add_metadata_field( $slug, $object_types = post, $args = array() )x_add_metadata_group( $slug, $object_types = post, $args = array() )
  20. 20. Even Further...• complex post to post (content to content) relations • allows web app functionality à la Rails/ Django • posts 2 posts plugin: http:// posts/• different page/content templates = different set of fields
  21. 21. ✔ Lessons Learned• use custom content types for anything that isn’t a blog post and isn’t a static page• if you’re a developer, don’t rely on the database to register CPTs• if you’re not a developer, hire a developer, learn to code (copy/paste) or use a plugin• best way to learn = read the codex, code and make mistakes
  22. 22. Extra links • Custom post type & custom taxonomy generator: generators/ • Joachim’s profile page (the SLD helper class plugin will appear here once it’s live): jkudish • Colin’s profile page: http:// • (recorded presentation will appear here):
  23. 23. Thanks!Any Questions?
  24. 24. Thanks! Any Questions? / /
  25. 25. Thanks!Any Questions?