WordPress Basics: Custom Taxonomies

In a recent posts we took a look at WordPress custom post types – what they are, how and why you should use them. Custom post types give you new types of content, custom taxonomies give you new ways to organize your content and you can apply them both to default post types, like Posts and Pages and to custom post types added by plugins.

What Taxonomies Are and How They Work

When you first install WordPress there already are two taxonomies you can use – categories and tags. Both of them are only assigned to Posts, so you can’t apply them to Pages. Main difference between categories and tags is that categories are hierarchical, while tags aren’t. With categories you can have a top level one and child categories under it, with tags something like that is impossible.

For each custom taxonomy you register, there’s two main choices to make:

  • Which custom post type(s) you want to assign it to
  • Do you want it to be hierarchical (like categories) or not (like tags)

For example, if you’re using Ingredients custom taxonomy you’ll likely only need to apply it to Recipes custom post type and you could make it hierarchical or not – both can make perfect sense. If you have Country of Origin taxonomy for the recipes, it’s clear that you’ll want to make it non-hierarchical.

Why You Should Use Custom Taxonomies

Custom taxonomies can help you organize your content in a more meaningful way. Yes, you can use tags for absolutely anything your posts are about, going back to recipe website example, one of your recipes could have all these tags: easy to make, chocolate, eggs, under 10 minutes. See the problem there? Easy to make and under 10 minutes are ways to describe the recipe, chocolate and eggs are ingredients. So, it is better to add Ingredients custom taxonomy to Recipes custom post type.

This will not only help you keep track of how many of your recipes contain chocolate, but it’s also something that can easily be displayed to your site visitors. This post is not about teaching you the “how-tos” of custom taxonomies, doing this is so easy you don’t need a developer to do it.

Making things even better, for each custom taxonomies you register you automatically get archives for all the terms. Your readers can just click chocolate in the ingredients list and hopefully avoiding gaining a few pounds after checking out your “recipes that contain chocolate” archives page.

Using Custom Taxonomies the Right Way

Code that registers custom taxonomies for you can be part of your theme or a plugin, but just like custom post types, there’s only one correct way to do it if you want to keep your custom taxonomies when you switch to another theme – use a plugin.

Featured image credits: Flickr

Slobodan Manic
I love working with WordPress and doing it the right way. Themes and plugins I develop have a common #1 goal: Keeping it as simple as possible for users to publish their content.
Slobodan Manic

@slobodanmanic

Data visualization freelancer
@scottbolinger Great read. Next bubble that doesn’t explode will be the first one :) - 1 day ago
Slobodan Manic
Slobodan Manic
Slobodan Manic

Latest posts by Slobodan Manic (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *