The days when WordPress was nothing but a blogging tool are long gone.

Today WordPress (WP) is powering e-commerce systems, enterprise CMS, booking engines, restaurants, NGOs, and so on. You name it, and WordPress has an answer to it.

And all this transformation was made possible with custom post types (CPT). If you have a business powered by a WordPress installation and are looking for greater power and expressiveness, custom post types are the answer.

But first, some history. 🙂

What are Custom Post Types in WP?

Custom post types . . . The terminology is a bit unfortunate, but there are historical reasons. Initially, WordPress was built with nothing but the idea of a blogging tool in mind. And what’s the fundamental unit of a blog?

That’s right, the post. So, for a long, long time, there was nothing but “posts” in the WordPress land. You created, edited or deleted a post; posts could be embedded into any page; and so on.

The explosion in WordPress’s popularity was unexpected. Suddenly, all websites were running on WordPress and businesses started feeling the need to extend WordPress to serve other business functions.

The WordPress core team responded by introducing custom data types, but since the term “post” was synonymous with “fieldset” in the WordPress world, the resulting feature was called Custom Post Types.

With Custom Post Types, you can group different fundamental input methods into an entity that makes sense on a business level.

For instance, in a laboratory management system, patient records can be a custom post type, with fields for necessary information, tests performed, expected values, measured values, etc. Once these custom post types have been created, the lab personnel can enter data into them without needing to worry about an external system.

Of course, custom post types, except when it comes simple data entry, won’t work on their own and some coding is required. There are powerful-enough plugins that can ease the job.

Next, let’s look at how to create a custom post type in WordPress.

Creating a Custom Post Type in WP – The easy way

The easiest and quickest way of creating custom post types in WordPress is by using a relevant plugin. There are many possibilities here, and my recommendation is to do a search, try a few plugins, and then settle for the one that feels intuitive to you.

For instance, if you choose to work with the Toolset Types plugin (which would be a great choice since the plugin has over 200,000 installations as of writing), here’s what you would do.

Once the plugin is installed, go to the Admin menu and click on Toolset -> Add new post type. Describe what you’d like to call your post type and what fields it should contain (the “Sections to display” section).

As soon as you hit “Save”, the new type is created is available in the admin menu!

Now try to create a new Dog. You’ll see that the standard WordPress “create post” UI opens up, except that this time there are only three fields that we said should be there: The title, the description, and the featured image. Custom fields, if any, would have also shown on this page. So fill them out, hit Publish, and your new Dog is published!

Now, what if you want to display the dogs as part of your blog posts? This isn’t usually possible, as custom post types are treated as entirely separate entities. Since they are not “posts”, they don’t show up in the blog list by default.

To add them to the blog, you’ll need to edit the functions.php file and add the following code:

<pre>add_action( 'pre_get_posts', 'add_dog_types_to_query' );
 
function add_dog_types_to_query( $query ) {
 if ( is_home() && $query->is_main_query() )
 $query->set( 'post_type', array( 'post', 'dogs' ) );
 return $query;
}
</pre>

I know what you’re thinking. This section promised the “easy way” of creating custom posts, but it’s anything but easy! I tend to agree, but in defense, I can only say that Custom Post Types is an advanced feature and will require WP development skills.

Custom Post Types – The hard way

So, what are the disadvantages of using a plugin for custom post types?

First off, plugins come at the price of inflexibility; yes, they allow you to get up and running quickly, but as soon you need to deviate from the default, it all goes for a toss. It won’t be hard to say that the plugins’ mess is what turns some businesses away from WordPress.

The remaining, hard, way is to go all in and code out your post types. Now, if you’re not a WordPress developer, this is not something you can hope to attempt, so it’s better to hire professional help. Still, if you’d like to take a look, the docs are here.

In the end, I’d like to repeat that custom post types are a powerful feature, but it comes at a cost. The complexity and maintenance of your site level up, and you’re even profoundly tied to the WordPress ecosystem.

So, it’s a path you should go down only when you’re confident that you want to make that commitment. 🙂