One of the most-powerful features of WordPress is the ability to create custom post types. Custom post types allow you to create your own type of publish-able content in your WordPress site. This comes complete with the block editor, support for taxonomies and metadata, archive pages, REST endpoints, and just about everything else that WordPress natively creates.
Custom post types are great because you get a lot of things for “free”, and it’s a consistent format that most WordPress developers will understand how to extend. This means if your plugin is something you distribute, more people are going to just “get it”. I recently did some work with Sugar Calendar, and it was delightfully straightforward. This is because the calendar feed is a native custom post type, so I just understood how to extend it because I’ve worked with custom post types in the past.
The problem is, since custom post types are so easy to create and extend, they tend to get misused by well-intended developers. Custom post types exist for a specific purpose – to create different ways to add, and display content on your site. If you’re using them for anything outside of that, you’re probably better off using a different approach, such as a custom database table with BerlinDB, or perhaps you just need to add a category to your posts.
It can be difficult to know when a custom post type is the right tool for the job. Sometimes it’s serious overkill, and you could do exactly what you need with a category. Other times, it’s flat out the wrong tool for the job. The goal of this post is to point out some signs that you probably don’t want to use a custom post type for your solution.
The Data You’re Saving Isn’t Content
This is the biggest sign that you should not be using a custom post type. Is your custom post type actually content? If it’s not content, it probably shouldn’t be a custom post type. When I refer to content, I mean any kind of content, regardless of if it is public or private. Things like:
- Recipes
- Upcoming Events
- Lessons
- Products
- Jobs
Are all examples of content. They get displayed on your website, benefit from having a post archive, and all have a single version of themselves (recipe, event, lesson, product, job). These are clear choices for custom post types.
You Don’t Need The Post Editor
This is another way to check to see if what you’re making is content. If you find yourself creating a custom post type, and you have this big beautiful Gutenberg editor in-front of you, and you realize that you have absolutely nothing to add to this screen, you probably don’t want to use a custom post type.
For example, let’s say you want to create a page on your site that features everyone on your team. Technically, this is content, and it does fit nicely as a custom post type called “team members”. So-far, so good right? Well, this all falls apart when you try to actually create a single team member in the block editor. Why? Because you really don’t need the editor – you just need a handful of metadata about that person so you can add them as a blurb.
Instead, You can build the team using Gutenberg directly, and then save it as a re-usable block if you need to use it elsewhere. If you find that you need to query the team, you can create a custom table in BerlinDB, or just add the team as users on your site and query them from that.
You Can Make it a Category or Tag instead
Before you make a custom post type, take a moment to ask yourself – can this simply be a category, or a tag? If the answer is yes, think twice before making it a custom post type. Categories get their own archive page in WordPress, so you can still create a dedicated page for them. This also allows you to easily blend this content alongside your blog content.
To put this another way – ask yourself do I want this content to display on my blog? If the answer is yes, then it should be a blog post with a special tag or category.
Conclusion
WordPress custom post types are really powerful, but they are not a be-all-end-all solution. There are many other ways to store, and organize data in you site. With careful consideration and thought, you can set your site up to use the best option for your needs.
Leave a Reply