WpW: Understanding Custom Post Types and Taxonomies
Welcome to another installment of WordPress Wednesday!
Today we are going to explore the often misunderstood concepts of Post Types and Taxonomies in WordPress.
About the word “post”
I think that much of the confusion around Post Types and Taxonomies is the multiple definitions of the word “post.” So, let’s get that cleared-up first thing. Here are the two ways in which “post” is used by WordPress:
- A post is any piece of content that is stored on a WordPress site.
- A post is a particular type of content, typically associated with a blog, and usually displayed in reverse-chronological order.
Another way to look at this is to say a post is a type of a post. Well, no wonder this is confusing!
Let’s decide right now how we’re going to use the word “post” so that we’re all on the same page. For the purposes of this discussion, we’re going to use “post” in the generic way (definition #1), using it to refer to any piece of content in WordPress. If we need to refer to the other kind of post (definition #2), we’ll call it a “blog post” just to be more specific.
Then we can say, a blog post is a type of a post, and that is actually pretty clear.
A post type is just like it sounds: a type of a post. All posts are stored in the same place in WordPress (the
wp_posts database table). Post types are used to differentiate the nature of the post.
WordPress has seven built-in post types:
- Blog Post
- Navigation Menu
- Custom CSS
Blog Posts and Pages are probably the most familiar of these. They are both stored in the database as posts, but their post type determines how they are handled by the front end.
For example, a particular post may be displayed on the home page alongside several others in reverse-chronological order if it has the post type “blog post.” Or it may appear as a link in a sidebar list of informational topics, if it has the post type “page.”
A taxonomy is a way of grouping together any type of object. Probably the most familiar taxonomy is “category” which allows you to sort blog posts into broad topics.
WordPress has four built-in taxonomies:
- Category (applies to Blog Posts)
- Tag (applies to Blog Posts)
- Link Category (applies to Links)
- Post Format (applies to Blog Posts)
A taxonomy can be hierarchical like categories (where one category can be a child of another), or they can be flat like tags (where all tags are on the same level).
As you can see by the third item in the list above, taxonomies are not limited to working with posts (remember, Links are not on the list of post types that we discussed earlier).
Custom Post Types and Taxonomies
With WordPress, it is possible to define custom post types and taxonomies. This is useful if you have content that doesn’t fit into the predefined mechanisms. You may have come across this before with certain plugins and themes that you’ve installed, although the use of custom post types and taxonomies is not limited to plugin authors. Any site owner with enough technical know-how can create his or her own set.
WooCommerce, for example defines a new post type “Product” and new taxonomies “Product Category” and “Product Tag.” By defining their own custom post type, WooCommerce is able to single out the posts that belong to their plugin and treat them differently than the built-in post types. And by defining their own custom taxonomies, they can easily group together like items within their custom post type. It allows them to use WordPress’ structure, without impacting any of WordPress’ built-in post types.
Let’s imagine you have a site that does automotive reviews. You don’t want to use blog posts for your reviews because you already use them for regular old blog posts. You can create a custom post type and call it Review. Then, you can create three new custom taxonomies: Model Year, Make and Model. These new taxonomies allow you to easily group your Reviews in useful ways.
Users browsing your site can see all reviews for 2013 models, or all reviews for Chevrolets, or they can specifically look for a review of the 2013 Chevy Impala, all through your custom taxonomies.
There is a lot more about this in the WordPress Codex. If you’re interested in building your own custom post type and taxonomy structure, you should take a look.
Next week, we’ll explore how LiteSpeed Cache for WordPress handles post types and taxonomies (both the built-in and custom varieties).
Have some of your own ideas for future WordPress Wednesday topics? Leave us a comment!
Don’t forget to meet us back here next week for the next installment. In the meantime, here are a few other things you can do:
- Subscribe to the WordPress Wednesday RSS feed
- Download LiteSpeed Cache for WordPress plugin
- Learn more about the plugin on our website