In WordPress, you can organize your content using taxonomies. Taxonomies like categories or tags help you keep things organized and easy to find. The interesting thing is that you can use a taxonomy for different post types like you can create a custom taxonomy 'Topic' for both 'Course' post type and 'Event' post type.
Although there are advantages to using this method such as it allows you to use the same name for the taxonomy, does it have any drawbacks? Will it affect how you manage terms in the admin or on the front end? Will it slow down your website? In this article, we will explore the pros and cons of using the same taxonomy for multiple post types in WordPress, shedding light on the considerations that can guide developers or website owners in making an informed decision.
Before going into the details, let's see what a taxonomy is and how to use it properly in WordPress.
What is a taxonomy in WordPress?
'Taxonomy' sounds a bit technical, but it's simply a way to categorize and sort your website's content in a logical manner. If you are familiar with 'Category' or 'Tag' for posts, then taxonomy is just the same for other custom post types (including posts, of course).
Think of taxonomy as a filing system for your virtual library. By creating different categories or tags, you can group similar types of content together, making it easier for visitors to navigate your site. It's like having different shelves for different kinds of books or separating your clothes into different drawers.
A taxonomy can have many terms. Each term is like a shelf for books or a drawer for your clothes. WordPress allows you to assign taxonomy terms to posts. It's similar to how you put a book on a shelf.
Technically, when creating a taxonomy, you establish a relationship between posts and taxonomy terms. This relationship is many-to-many (or N-N), which means a post can belong to multiple terms. And a term can have multiple posts (in this article, 'posts' mean not only the default WordPress posts but also pages and any custom post types).
You can also see this relationship in the WordPress database table wp_term_relationships
:
Because of this implementation, querying posts by taxonomies is much faster than by custom fields. So, if you're using custom fields for grouping or categorizing posts, consider changing them.
Why do you want to use the same taxonomy for multiple post types?
Sometimes, it becomes natural for you to use the same taxonomy for different post types, especially if the post types are related. For example, if you have a website about e-learning, you might have a 'Course' post type for students to join to learn, and also an 'Event' post type for meetups or conferences that discuss the same topics as in your courses. In that case, you might want to organize both courses and events by 'Topic'. The name 'Topic' comes to you naturally as it's logical and is used widely on many websites.
When adding the same taxonomy to different post types, you can access the taxonomy management page from multiple locations in the admin menu. WordPress automatically creates a sub-menu for the taxonomy under each post type top-level menu:
The interesting thing is that when viewing the taxonomy terms, you'll see all the terms you created for all post types! No matter which sub-menu you click on. Like if you click on the 'Topics' sub-menu of the 'Course' post type, you will see not only topics for courses but also for events! This will help you manage all terms in one place and avoid any duplication.
And not only on the back end but when viewing a taxonomy term on the front end, you'll see all posts of all the post types at once:
That helps your audience can browse all the related content (in this case courses and events) in the same place, and of course, go to your course and event easier.
So, using the same taxonomy for multiple post types sounds good for this situation. But does it have any disadvantages? Let's find out below.
Problems of sharing a taxonomy across multiple post types
The biggest problem happens when your post types don't relate to each other. Let's say you have 'Book' and Event' post types on an e-commerce website for selling books. 'Book' is like a product, and 'Event' is for company-sponsored events (like marathons, or a festival). Both can have the same 'Topic' taxonomy. However, a topic like 'parenting' seems to be normal for books, but not for events.
In that case, using the same taxonomy confuses both the website owners and users. On the back end, when you navigate to Books > Topics and see also topics for events and vice versa? That's confusing and is also dangerous if any of your website editors delete those terms (because they're not for books, aren't they?). This might also lead to a break in the front end: broken link, page, or menu.
This problem also happens when editing a post on the back end and seeing the list of taxonomy terms from another post type:
On the other hand, viewing a taxonomy term on the front end will list all posts from all connected post types. It's worth noting that some post types are styled differently: a book might have a cover image and the book title as well as a price while an event has the title, image, date, and location. This makes the styling on the front end much harder to show them properly. You might end up with conditional styling for each element of the post in the loop, which is probably an advanced topic for WordPress developers.
You might also concern about the performance of using different taxonomies for post types. From what we showed above, WordPress uses the same table for all the terms-posts relationships. That means no matter how many taxonomies you have on your WordPress website, the database is technically the same as using one taxonomy for multiple post types. So, in terms of performance, there is no gain or no pain in either approach.
What should you consider when creating a taxonomy?
Because of the reasons above, when creating a taxonomy, please consider the following issues if you want to use it for multiple post types:
- Are the post types related? Is managing the same taxonomy terms for post types logical? And is it ok to use a term for all of the post types?
- Is showing all posts of your posts types on the same page on the front end (the taxonomy term page) ok? Do you have any trouble styling posts differently?
If any of the answers to the above questions is 'No', I'd suggest you use different taxonomies for each post type. The good thing about taxonomies in WordPress is that you can have two taxonomy with the same name: 'Topic' for books and Topic' for events, but they're actually different taxonomies. Doing so by setting different slugs for the taxonomy.
If you use MB Custom Post Types & Custom Taxonomies plugin to create taxonomies, simply set the slug in the main screen:
With this technique, you keep taxonomies separated but still have the same labels. So, it's not confusing when adding terms on the back end as well as viewing terms on the front end. Everything is in the right place.
Conclusion
The decision to use the same taxonomy for multiple post types in WordPress involves weighing the pros and cons to determine the best approach for your website. By answering the above questions, I hope you have your own answers. The answer must be applied to a specific situation, and there is no one size fits all. Whether you choose a unified taxonomy or opt for separate taxonomies, remember that the ultimate goal is to create a user-friendly and organized website that effectively delivers the right content to your audience.
This is fascinating and it strikes me that organising content on websites is one of the least well understood aspects of building them. I know this because I spent so much time trying to understand it. Building 'hubs' for different topics, and then grouping different types of content would be productive - as would building hubs for specific target audiences - parents for example. This is different from having a common naming structure that is scattered across different post type areas?
Yes, it's different. I think "hubs" is a taxonomy and each "hub" is a term. You're using it for (as I understand) a single post type.