When I first started working with WordPress I kept hearing people talk about custom post types and taxonomies. Since I was new to CMS and web development in general I wasn’t sure what everyone was talking about. I started digging into what post types and taxonomies are and ended up confusing myself even more at first. Finally, one day it clicked for me and I realized I was over complicating the way I thought about post types and taxonomies.
This is a two-part series. Here I’ll just be breaking down what custom post types and taxonomies are along with an example of how they work inside WordPress. This post will not contain any code examples. If you want to see the code behind it all, you can check out part two, Custom Post Types 2: With a Vengeance (And Code) , over on kennyinthewild.com!
Custom Post Types
Let’s start with custom post types. Post types are used to house and store types of data and content. WordPress has 5 default post types (Post, Page, Attachment, Revision, and Navigation Menu), although you will only see 2 of them on the back end. The others are either not shown in the menu or are a part of other functionality. So as you can see, post types can provide a wide array of functionality.
As an example, let’s say we run a site that sells cell phones. We need a way to categorize cell phones by Brand, Operating system, and Model. This is a great use for post types and taxonomies.
First we would need to create our custom post type. There are two types of post types, hierarchical and non-hierarchical. Hierarchical post types allow the user to connect their post type and content to a parent post type. Non-hierarchical post types do not use/need a parent post type.
Since we won’t need a parent post type for our example, let’s use a non-hierarchical post. We’ll keep it simple and call our non-hierarchical post type “Phones”. Before we start adding the phones we have in stock, we will need a way to categorize/organize the phones. This is where taxonomies come in.
We can create a custom taxonomy to help us better organize and categorize our content and data. Just like post types, taxonomies can be hierarchical and non-hierarchical.
In this example, “Operating systems” will be non-hierarchical and “Make and Model” will be hierarchical. Our “Operating Systems” taxonomy is a non-hierarchical taxonomy because iOS is not installed on Android devices and vice versa. There is a clear line of division between the two operating systems and they will never need to relate to each other. That’s why a non-hierarchical taxonomy is perfect for connecting all the content for our “Operating Systems” taxonomy.
The other taxonomy we are using is called “Make and Models”. This will be used to catalog the makers of phones and the series the phone is in. In the example below you can see we are creating a new post featuring the Samsung Galaxy s6. We assigned it to the Android operating system and apply the “Samsung” and “Galaxy Series” tags to the post. Lastly, we titled the post to pertain to the specific phone we were talking about.
Now if a user comes to our site and is looking for information about a specific phone, they have multiple ways to get access to the information about the device they are looking for. They could search Samsung and they would receive a list of all Samsung devices on our site. They could also search Galaxy series and they would receive a list of all devices in the Galaxy series.
Another way to think of custom post types and taxonomies is that the post type is a general description of the data/content your are describing, which in our examples case would be phones. The taxonomies allow us to be more specific by describing the make,model, and operating system. In our example above we used the “Samsung Galaxy S6” post to let our users know it was an Android device made by Samsung in the Galaxy series.
Custom post types and taxonomies are a staple of WordPress, but they can be confusing to users who are just entering the community. I hope my explanation helped! If you have any question or comments feel free to leave them in the comment section below.