WordPress Custom Post Types and Taxonomies: Introduction Redefined
Out of the box, WordPress has several post types already defined and the most common ones we interact on the daily basis are posts and pages.
Taxonomy is the schema of classification. It could be defined as the organizational system that allows us to relate one item with another item with other similar items in hierarchical and non-hierarchical groups
Let’s understand it by a simple real life example;
In your Wardrobe, you have your shirts in one section, your jackets in another, your pants in another and so on. But whats the benefit of using this technique? Let’s say you want to find some pant, you just go to the section containing your pants only. Simple enough? These are hierarchical system or categories, a type of taxonomy. And every item have some tag on it, like its size, color and so on, these are named as tags, which are non-hierarchical.
In WordPress, we have two default taxonomies, that you normally use all the time. The first one is category, every post must have a category. They are displayed as hierarchical system, so that means we can have parent/child relationship. Moreover categories are the main organisational method within WordPress.
On the other hand, tags are optional. You don’t have to use them, but you can use them whenever you want, they are non-hierarchical, meaning that they are not related to one another & they are considered as the secondary organizationals method in the WordPress.
When you’re creating custom taxonomies, you can either create hierarchical(category) or non-hierarchical(tags). These taxonomies can be applied to one or several post types including posts. Custom taxonomies can have custom index and archive template. These are usually displayed along-side categories & other meta content. Custom taxonomies allows for more advanced Organization of content.
Creating a new Custom Post Type & Taxonomy
So, When you’re creating a new custom post type or taxonomy, the very first question arises in your mind is where should you write your code in WordPress theme structure.
Well there are two options, one is to create a simple plugin, & other is to write it into your functions.php. Now, there are benefits and drawbacks of both, such as,
A Plugin can be turned on and off, and it could be specific to each theme you’ve created. This technique is used in most of the cases.
Whereas, on the other hand, if you write your custom post type and taxonomy code in your theme directly, it is only for custom builds & its content is theme dependent & allows for some advanced functionality.
It’s completely one’s individual choice of how to use it in your theme. In the next article I’ll explain how to create custom post type & taxonomy using both described techniques & we’ll find out more about custom post types and taxonomies.
If you have any questions, write me a comment below or find me at twitter.