The ability to add Custom Post Types, Taxonomies and Custom Fields (meta boxes) make WordPress the number one CMS in the world. They are insanely useful and gives you the ability to transform a simple WordPress site into a unique CMS. Up until WordPress 3.0, Custom Posts Types weren’t supported, which was one of the biggest disadvantages compared to its rivals. Before we begin, I’d like to inform you that this is an advanced article – especially if you’re hearing these terms for the first time. I’ll try to make it comprehensive, apt for beginners. So stick around, you might learn something new!
This post will be using a free plugin called “Types” to generate these, if you would like to read in detail about them see these tutorials :
What are custom post types?
Custom post types is a feature introduced in WordPress 3.0 which allows you to add you own post/content type. Please don’t confuse the term ‘post’ with ‘blog post’ as the former is a very generic term. ‘Post type’ refers to the content type. Hence, a ‘ blog post’ or a ‘page’ is actually a type of post/content, which is predefined in WordPress. You can define your custom post type. Here’s an example to help you understand:
Suppose you’re running an entertainment site – where you add the week’s top music albums, movies, TV shows, events, etc. Each of these entities would make up a custom post type. Once you’ve registered a new custom post type – say Books, on the admin dashboard sidebar menu, you would see a new entry called Books. Here’s how it looks like:
How to create a new custom post type in WordPress?
Creating a new custom post type requires you to define a custom post type with the required array(s) and variables, and register it via an action in the function.php file. Sounds looney? Introducing the Types plugin. With this one-of-a-kind WordPress Swiss knife, you can create, update and edit custom post types, fields and taxonomies with nothing but a few clicks of the mouse (and keyboard of course). First, you need to download and install the Types – Custom Fields and Custom Post Types Management plugin. You could either upload the contents of the plugin via FTP or directly add it from Plugins >> Add New. Next, activate the plugin.
Then navigate to Types >> Custom Post Types and Taxonomies >> Add Custom Post Type
Our objective is to add a custom post type called “Books”. Kindly note, that I have already registered 2 custom taxonomies called Genres and Authors (see tutorial below). Thus we enter the relevant data (see screenshot below) and under the “Select Taxonomies” box we check only “Genre” and “Authors”. When you’re trying out this tutorial for the first time, check “Tags” and/or “Categories” in place of “Genres” and “Authors”. Once you create a new custom taxonomy, you can edit this custom post type and change the taxonomies accordingly.
In the Display Options tab, you could check the options (meta boxes) that would be visible by default in the Edit page for the custom post type you’re creating. I’ve selected a few which are relevant for Books.
Since books can be hierarchical – like the Harry Potter novel series, we check the “hierarchical” option, found under the “Advanced” tab.
Once done, select Save Custom Post Type. If you’ve entered everything properly and there are no conflicts, then you should see this message:
Custom Taxonomies and how to create one:
Remember 9th grade Biology class? The plant/animal kingdom? That’s probably where you heard the term ‘taxonomy’. Here’s a definition:
The branch of science concerned with classification, especially of organisms and WordPress post types.
Tags and Categories are the default taxonomies in WordPress and you could create as many as you like. With the Types plugin you can quickly create new taxonomies, customizable with the multitude of options available within the plugin. Let us create 2 custom taxonomies for our custom post type – “Books”.
To create a taxonomy, navigate to Types >> Custom Post Types and Taxonomies >> Add Custom Taxonomy
- The first taxonomy is called “Genre” which would have a hierarchical layout – much like the default Categories. Each book can now have one or more genres.
- The 2nd taxonomy – “Authors” will have a flat, ‘Tags’ like layout. Now each book can have one or more authors, entered via comma separated values – just like tags.
Both these layout options – ‘flat’ and ‘hierarchical’ are found under the Advanced box. Once done, select the Save Custom Taxonomy Button.
Now that you’ve registered 2 new taxonomies, its time to edit the “Books” custom post type that you created earlier and change its specific taxonomies. I won’t be writing a step-by-step tutorial on this one – think of it as an exercise for the reader. Of course if you get stuck, I’d be more than happy to help you. Once you have edited the Books post type with the specific taxonomies, the “Custom Post and Taxonomies” page under “Types” would look something like this:
Custom post and taxonomies are an extremely powerful field in WordPress. Once you’ve got a hold of the two, there’s virtually no stopping you from creating almost any type of CMS. And with the help of the Types plugin, you can incorporate a multitude of custom post types and taxonomies in your website. Here’s an example of what can be achieved via custom post types: