In this article, we’re going to show how you can create and use custom taxonomies in your WordPress posts. We’ll also explain what custom taxonomies are and how they’re used in WordPress. In order to create our taxonomies, we’ll be using the Custom Post Type UI plugin.
What is a Custom Taxonomy?
Taxononies are what WordPress uses to organize your posts. You may already be familiar with the default taxonomies that come with WordPress: categories and tags.
You use categories and tags alongside posts. For example, if your posts are about music you may have a category called Rock and Roll and a sub-category for 1950s. You may also have tags like Buddy Holly, The Drifters, or Elvis Presley associated with various posts. These help your readers know what the post is about and find other related posts. This can also help your site be more easily readable by search engines.
Hierarchical
Taxonomies can have parent-child relationships that make them “Hierarchical”.
For example, categories can have sub-categories and sub-categories can have sub-categories of their own and so forth:
- Music (Parent)
- Classical (Child)
- Rock (Child)
- Hip Hop (Child)
- Movies (Parent)
- Action/Adventure (Child)
- Sci-fi (Child)
- Space Opera (sub-Child)
- Flying Saucers (sub-Child)
- Documentary (Child)
Notice above that parent and child relationships are virtually unlimited in terms of how complex the hierarchy can be. Child nodes can have their own children. You determine the level of depth required for keeping your site organized and user-friendly.
Non-hierarchical
Taxonomies can also be non-hierarchical, meaning they have no parent-child relationships. This is how post tags are used. In this scheme, each term associated with a post is of equal value. Again, how you choose to use these terms depends on how you want to organize your post content.
How to Register Taxonomies
For our demonstration, we’re going to be using the Custom Post Type UI plugin. In addition to creating custom post types, this plugin lets you easily create taxonomies that you can associate with your post types.
For example, you can create a custom taxonomy for your default WordPress posts or a new category or tag for a custom post type.
- Log into your WordPress Dashboard
- Choose Add/Edit Taxonomies under CPT UI (left panel)
- Fill in the label fields
Be sure to pay attention to which labels are singular and plural. This will make usage of your taxonomy within the WordPress interface easier.
Which Settings Should I Use?
For the most part, the default settings are acceptable for creating a new taxonomy. Here are some of the settings you may want to pay closer attention to in customizing your taxonomy for your needs:
Setting | Purpose |
---|---|
Taxonomy slug | Part of the URL structure of this taxonomy (will also display an archive page) |
Attach to Post Type | To which post type will this taxonomy apply? |
Hierarchical | Will this taxonomy have parent-child relationships (like a category) or remain non-hierarchical (like a tag)? |
Using Your Custom Taxonomy
You should now see your custom taxonomy available under the post type it applies to. Here you will be able to manage your custom taxonomy by adding new ones and editing the ones you’ve created.