how to create custom taxonomy in wordpress

0 140

Taxonomy is a feature to group content like posts, links in a structured way. For example, category and tag are the inbuilt taxonomies in WordPress to group posts. The category is a hierarchical taxonomy and the tag is an example of non-hierarchical taxonomy.

WordPress allows us to create custom taxonomies. It can be either hierarchical or non-hierarchical. It is introduced in version 4.0 Here we are going to see how to create a custom taxonomy in WordPress.

Register Custom Taxonomy

There is a function named register_taxonomy() to add and register our own custom taxonomy in WordPress. We have to hook this function to the init action in functions.php

Here is an example code for creating custom hierarchical taxonomy named Awards. The value we are giving in slug option will be used in the taxonomy page URL. And the code is,

Taxonomy Terms

We can add more groups under taxonomy. These are called taxonomy terms. In this example, we are registering the custom taxonomy for a post. So we can see this under post menu in WordPress Admin. The screenshot is,

By using this menu, we can navigate to the page to add new terms to this custom taxonomy. This screenshot shows the page to manage custom taxonomy terms.

You might also like More from author

Leave A Reply

Your email address will not be published.