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.
2. Organizing Content of
Different 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. Back in the day...
• Websites were simpler... ?
• Created custom architecture with pages
• Different content types could be “faked” with
categories and category navigation
4.
5.
6. What are custom post
types?
• 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
7. Advanced uses of CPTs
• Products (WP E-Commerce uses it -
http://getshopped.org/)
• Job Postings
• Testimonials
• Newsletters
• Possibilities are endless!
8.
9.
10. Registering Custom Post
Types
Graphical/easy way:
• Plug and play, simple interfaces
• Custom Post Type UI - http://
wordpress.org/extend/plugins/custom-
post-type-ui/
• GD Custom Posts And Taxonomies Tools
- http://wordpress.org/extend/plugins/
gd-taxonomies-tools/
• More Types - http://wordpress.org/
extend/plugins/more-types/
• Lots of other examples
15. Code Method
register_post_type();
• http://codex.wordpress.org/
Function_Reference/register_post_type
• core function
• lots of $args for lots of possibilities
18. 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
19. Some Shortcomings of
WP 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.
20. Alternate Code Methods
• Smarter Custom Post Types by Matt Wiebe:
• http://somadesign.ca/projects/smarter-
custom-post-types/
• now obsolete because of 3.1’s archive/
permalinks abilities
• Our own SLD Custom Content & Taxonomy
• https://github.com/jkudish/SLD-
Custom-Post-Types-Taxonomies-for-
Wordpress
• wrapper plugin/class for
21. Taking CPTs even
further
• 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()
http://codex.wordpress.org/
Function_Reference/register_taxonomy
24. Taking CPTs even
further
• 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()
• http://codex.wordpress.org/
Function_Reference/add_meta_box
25.
26. Meta Boxes
• similarly to content types & taxonomies,
there are GUI plugins to register meta
boxes
• More Fields: http://wordpress.org/
extend/plugins/more-fields/
• Advanced Custom Fields: http://
wordpress.org/extend/plugins/
advanced-custom-fields/
• Verve Meta Boxes: http://
wordpress.org/extend/plugins/verve-
meta-boxes/
27. Easier Meta Fields
• Custom Metadata Manager by Mohammad
Jangda
• http://wordpress.org/extend/plugins/
custom-metadata/
• easy wrapper functions for adding meta
boxes and custom fields
29. Even Further...
• complex post to post (content to content)
relations
• allows web app functionality à la Rails/
Django
• posts 2 posts plugin: http://
wordpress.org/extend/plugins/posts-to-
posts/
• different page/content templates = different
set of fields
30. ✔ 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
31. Extra links
• Custom post type & custom taxonomy
generator: http://themergency.com/
generators/
• Joachim’s WP.org profile page (the SLD
helper class plugin will appear here once it’s
live): http://profiles.wordpress.org/users/
jkudish
• Colin’s WP.org profile page: http://
profiles.wordpress.org/users/cvernon
• WordPress.tv (recorded presentation will
appear here): http://wordpress.tv/