If you’ve decided that you need custom post types in your life, great! Your next question may be, “How on earth do I get them here with me?”
The great news is that, like pretty much everything else in the WordPress ecosystem, you have options. Some are better than others, and certainly some are easier than others. This is not meant to be an exhaustive list, because I have neither tested nor researched every option out there.
Before you do anything to actually create your Custom Post Type (CPT), think about how you’ll use it, and what options you might require.
- Will it be a pretty simple content type, or will you need to categorize it using one or more taxonomies (think categories and tags)?
- Will it be date based, like posts?
- Will you need a main archive page for your content type?
- Will you want your content type to have a featured image, support comments, or even have a place to add content at all?
- Will each instance of your content type need to follow a specific pattern in terms of its data?
Don’t worry, none of these are really set in stone until you’re actually using your new CPT, and some of them can be modified even then, but it’s a good idea to think this through before you sail straight in.
Why would you want to do this yourself if you could have a custom post types plugin do it for you? Or why would you have a plugin do this if you could do it yourself? It really depends on your comfort level, how much you want to rely on someone else’s system, and how much customization you need to get into. Honestly, registering (or building) a post type is pretty simple, but bending it to your will can get tricky.
Use a Plugin
This is probably the easiest way to build your Custom Post Type. You can use a plugin which will automatically generate the code you need to make your CPT happen. Some of them give you code that you can export; some require that you use the building plugin for the duration, so think through your options carefully. Here is a totally non-exhaustive list:
WP Types: I’ve used Types (and its counterpoint, Views) on one project. Types is fairly easy, but if you use it to create your CPT, you need to keep using it. I did not love the Views component ($.02).
Easy Content Types: This is indeed a very easy plugin to use. One thing I liked about it was that it generated code that I could drop into my theme or plugin, without needing to have Easy Content Types installed on the site itself. One consideration is that although it works, it’s no longer actively being developed.
Pods: I played with this one while writing this post. It seems nifty, but looks like if you use it, you’re committed to staying with it.
Do It Yourself
If you’ve decided you’re the Tim Allen of WordPress and want to DIY, you have two options: 1) add your CPT in your theme; or 2) add your CPT in a custom plugin.
Actually, I lied. Although you can add your CPT within your theme’s functions file, it’s not a good idea, so I hereby take it off the table as an option. Why? The main reason is that CPTs are (kind of) forever, like diamonds, and themes only last a day, or a month, or a year. Trust me, you do not want to have to dig out your CPT code every time you change a theme.
Also, if you need to troubleshoot for a possible code conflict, the first rule of WordPress troubleshooting is to activate one of the default WordPress themes (Twenty Fifteen, etc.). If you’re trying to troubleshoot something with your theme, the problem may go away, but so will your CPT.
In this post, I’m not going to go in depth about how to build your own plugin for your CPT, but if you want to peek ahead, I’ve built a dead simple example plugin, which I’ll unpack a bit in a future post.
In the meantime, even if you’re building your own plugin, you absolutely do not have to build your CPT by hand. There is a great online tool called Generate WP, which you can use to build not only post types, but also register taxonomies, and do quite a few other awesome things. It’s totally free. You just put in your information, the generator generates your code, and then you copy/paste. Even if you want to tweak it a bit after, it’s great for making sure you don’t miss anything.
So, depending on your comfort level, and how complex you might want to get, using a Custom Post Types plugin may be the safest way to go for building out your new content type, but it’s worth looking into the options of how to do it yourself.