If you have ever stepped foot in the realm of WordPress, you might have come across the terms ‘Category’ and ‘Taxonomy’. Category is a pretty straightforward term and is pretty clear to the user. Users create posts and group them in different Categories. But the term taxonomy is a bit baffling for a novice user. People struggle to find the exact definition of the word and its application in WordPress. In this article, we will try to decipher taxonomy and what is the difference between Taxonomies and Categories.
What is a Taxonomy?
In WordPress language, a Taxonomy is a grouping of posts. Any parameter according to which the posts can be grouped falls under taxonomy. Now, since categories are also a parameter used in the grouping of posts, so they also fall under the umbrella of taxonomy. Category is the only Default Taxonomy that is hierarchical i.e. It can have child and grandchild categories.
In general, WordPress offers 4 taxonomies by default – ‘category’, ‘post_tag’, ‘post_format’ and ‘link_category’. Most of you must be familiar with ‘category’ and ‘post_tag’. These are the most popular taxonomies. Categories can be customized from Posts > Categories in the Dashboard while Tags can be made on-the-go while creating or editing posts. There is no limit to the number of tags that can be created. You must be familiar with the ‘Tag Cloud; widget. It is also a form of taxonomy.
Post Format is another form of Taxonomy in which the posts can be grouped. Unlike Categories or Tags, you cannot add a Post Format. There are 9 Post Formats in WordPress – Aside, Gallery, Link, Image, Quote, Status, Video, Audio and Chat. Most of these are self-explanatory. You can read about them in the Codex.
The last of the default taxonomies is the Link Category. It is not used much in WordPress but certainly deserves a mention. It is the categorization and organisation of links to display them in a more sophisticated way on the site. These are used internally and are not in the hands of the user.
Custom Taxonomies
Apart from the default taxonomies, WordPress also gives us the option to create Custom Taxonomies. In fact, this is the feature that makes it really powerful. Posts can be grouped in all sorts of ways. Many plugins have made tremendous use of this feature. In WooCommerce, Product Categories are a form of Custom Taxonomy. Custom Taxonomies can be created using the function register_taxonomy
. I would not go into detail about the creation of a custom taxonomy here as it is explained in detail in the Codex.
Custom Taxonomies can be both hierarchical or non-hierarchical depending on our requirement. If the posts are such that they would need to be compiled in a hierarchical model than hierarchy can be enabled in a custom taxonomy.
Once a taxonomy has been created, it can be used to fetch posts using the WP_Query loop. The 'tax_query'
argument is used to deal with a custom taxonomy.
Taxonomy is a general term referring to a grouping of posts while Category is a subset of Taxonomy grouping the posts in ceratin categories.