Overview: How Taxonomy Works In WordPress

In an upcoming post, I’m going to describe how one goes about hooking taxonomy changes in WordPress when building a plugin, widget, theme function or other modification.

To support that post, this post will review how taxonomy — categories, tags and the like — work in WordPress.

Prior to WordPress version 2.3, there were only two WordPress taxonomies: categories and tags.

A category dictated the “section” of a website to which a post belonged; a tag allowed one to quickly interrelate posts, usually within the same category.

That’s the way this blog uses taxonomy. I have categories which group together posts by the programming language, technology or content of the post, such as PHP or WordPress. I use tags to quickly tie together posts that have a common theme, such as latitude / longitude or DOM images.

Since version 2.3, we’ve been able to create custom taxonomy. That’s resulted in two big changes: Effectively eliminating the distinction between a tag and a category, and allowing us to create additional taxonomies, to even more narrowly define a subject.

Taxonomy Defined

So what is taxonomy? In short, it’s a way to group together, or classify, information so we can more quickly find what we’re looking for.

Take, as example — since this is the Internet, after all — house cats.

Like all animals, we can easily place a house cat into a taxonomy of all living things by considering its scientific classification:

The scientific classification for a house cat.
The scientific classification for a house cat: Kingdom > Phylum > Class > Order > Family > Genus > Species > Subspecies.

But there are also a lot of different types of cats:

CAT BREEDS by Yasmine Surovec, on Flickr
CAT BREEDS by Yasmine Surovec, on Flickr

In this example, under the pre-version 2.3 taxonomy of WordPress, the scientific classification of the cat could be considered its WordPress category, and the different types of cat — Maine coon, Bengal, American shorthair, etc. — could be considered its tag.

Whenever we’re talking about a house cat, regardless of its breed, we’re talking about the same animal; that is, the category of animal is a cat, versus a dog or a monkey or a whale or an amoeba.

By the same token, any time we’re talking about a cat, it belongs to at least one, but perhaps several, breeds; so we may want to tag it with one or more breeds, so that cats similar to this one can also be found.

It’s the same in pre-version 2.3 WordPress. We created posts in categories, basically for navigation purposes; a post’s category told us what section of the website we were in (e.g., the cat section), and its tag allowed us to find similar posts, usually within that category (e.g., the Siamese cat tag).

Taxonomy In WordPress

Let’s consider the out-of-the-box way taxonomy works in WordPress. If you do a clean install, you’ll wind up with something like this:

This diagram shows the default taxonomy for WordPress post content types (blue).
This diagram shows the default taxonomy for WordPress post content types (blue).
The Posts menu in the WordPress Dashboard.
The Posts menu in the WordPress Dashboard.

The yellow taxonomy is effectively a reproduction of the pre-version 2.3 categories; the green, a reproduction of the old tags. When you look at the WordPress Dashboard and see Categories and Tags under the Posts menu, that’s the yellow and green taxonomies, respectively.

After version 2.3, it became possible to create custom taxonomies. That is, rather than being restricted to putting a post into only one category, and applying only one set of tags to it, we can now create multiple category types, and multiple tag types, to apply to a post.

This functionality is most commonly applies when also using custom post types, but it’s not necessary; you can create custom taxonomy for the built-in post object.

For example, WordPress introduced post formats in version 3.1.

This is basically a kind of taxonomy that tells a theme to use a different template, or to somehow treat a post differently, based on it being an aside, quote, audio, video, etc. Posts are still posts, but a post’s format might not be the same as other posts; just like all Persians are cats, but not all cats are Persians.

Taxonomy To Isolate And Unite Content

Let’s look at a conventional use of custom taxonomy: grouping together like posts, for a specific purpose.

Let’s say you’re running a retail business site, and you want to list off your store locations. A way to do that would be to create a custom post type called “store,” which might, for argument’s sake, contain meta information about its location, hours of service, phone number, etc.

In addition, you might want to apply a custom taxonomy to each of those stores. For example, maybe you want to categorize your stores by the types of products they offer.

Hardware shop, Molesworth Street, Wadebridge, Cornwall, England.
Hardware shop, Molesworth Street, Wadebridge, Cornwall, England. Copyright David Hawgood and licensed for reuse under this Creative Commons Licence.

If you’re a hardware store chain, for example, maybe some of your stores offer lumber, but others don’t. It would make sense, in that case, to have a custom taxonomy term named “Lumber,” which people could click, and which would only show those stores that have lumber.

At the same time, you might also want to have tags that apply to your stores, which perhaps relate to specific products. In fact, perhaps you have a second custom post type, called “product,” which lists off some of the things you really want to highlight.

In that case, you could create a custom taxonomy — let’s call it “featured-products” — which would apply to both the store and product custom post types. By tagging each store and product with the same tag, you could effectively interlink them, making it easier for people to move back and forth between the two.

So, if I’m looking at a store, I could see a tag, such as “lawnmowers”, click it, and see all the lawnmowers you sell; or, if I am looking at a product tagged “lawnmowers,” click that and see all the stores that sell them.

Here’s how that would look in the WordPress database:

This diagram shows two custom post types (blue), with independent custom categories (yellow), but which share a custom tag group (green).
This diagram shows two custom post types (blue), with independent custom categories (yellow), but which share a custom tag group (green).

That’s the power of custom taxonomies, which is why it’s a good thing, overall, that these changes happened.

But when it comes to knowing when one of these taxonomies has been changed, or trying to change them via a plugin, theme function or the like, it can be confusing. We’ll tackle that next.

All links in this post on delicious: https://delicious.com/dougvdotcom/overview-how-taxonomy-works-in-wordpress

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Check out the Commenting Guidelines before commenting, please!
  • Want to share code? Please put it into a GitHub Gist, CodePen or pastebin and link to that in your comment.
  • Just have a line or two of markup? Wrap them in an appropriate SyntaxHighlighter Evolved shortcode for your programming language, please!