Beginners Guide to Custom Post Types

Beginners Guide to Custom Post Types

The WordPress development team have been slowly expanding on the concept of custom post types over the last few versions of WP to the point where we are at now, where they have become a popular way to manage content more efficiently on a WordPress site.

But what are custom post types? This article will give you a beginner’s guide to:

  • What they are
  • What you can do with them
  • How you can go about using them on your site

Life Before Custom Post Types

Before custom post types, all posts were essentially the same, whether they were used for displaying a blog entry, an image gallery or a product listing on an eCommerce store. Since the arrival of custom post types it is now possible to create a new type of post for different types of content.

Enter the Custom Post Type

These new types of post are based on the standard post in WordPress except that they have a different value in the post_type field in the WordPress database. This value could be anything of your choosing such as ‘products’, ‘images’ or ‘staff’. While they might sound like categories or tags, they are not.

Once a custom post type has been created, there will be a new section in the WordPress admin sidebar menu just for that post type. This new menu item looks like the regular post menu with an ‘add’ button and whatever else you have chosen to display on the menu. The Ideas plugin is an example of a simple use of custom post types:

custom-post-types-ideas-example

Meta Boxes

As well as creating a new menu item for custom posts, these post types can also be given their own meta boxes. These boxes work in a similar way to the fields that appear beneath the regular editor on the ‘edit post’ screen in WordPress.

While a regular post in WordPress will store additional information alongside the actual post content such as the date it was published and by which user, with a custom post you can add your own meta boxes to record data relating to that particular post.

For example, if you were creating a custom post type for different types of cheese, the meta boxes you might want to use could include flavour and strength and it might look something like this:

Custom Post Types

Here you can see I have created a custom post type called cheese and for that custom post type, the regular post editor is turned off since I don’t want to enter any post information.

Instead, two meta boxes have been created. One is to record the strength of the cheese and uses a drop down menu, while the other is to record the flavour, using a text box.

While this is a basic example, you should be able to see the potential for creating custom post types for cataloguing data.

Along with the use of custom taxonomies you can go even further towards cataloguing your posts in a way that makes them easier for your users to navigate.

Custom Taxonomies: Another Type of Category

While the regular posts that you write for your blog will go into the categories you have created for them, the content you add to your site using custom post types, such as products, probably won’t fit into those regular blog categories.

While you could create new regular post categories for your custom post types, this isn’t the best solution as it can lead to clutter and confusion for your users and make the task of filtering posts and listings less efficient.

When it comes to categorising your custom post types, in most cases using custom taxonomies is the answer.

Think of custom taxonomies as a folder that contains its own categories. For example in a standard WordPress installation you can create categories using the category menu item. By creating a custom taxonomy, you could have a further menu item under the posts sub menu for categories related to a certain type of post. This could be for product posts and in this custom taxonomy folder could be categories relating the products such as product types.

Here is a custom taxonomy I have created to illustrate this point:

 

Custom Taxonomies

Here you can see that under the posts menu there is a new item called ‘Products’ and that the process for creating new products is the same as creating regular categories or tags, in that you add a name, a slug and a description after which they can be assigned to posts in much the same way as tags and posts can be.

Even if you don’t use custom post types, creating your own custom taxonomies gives you another way to categorise or tag your content. For example if you had a site about WordPress you could tag this guide with ‘custom post types’, put it in the ‘guides’ category, as well as applying a custom taxonomy called CMS using the CMS category ‘WordPress’.

You could then display the list of categories from the custom taxonomy you created, giving your users another way to find the posts they are looking for. In this case the blog could display a list of regular tags, a list of regular categories and a list of categories from the CMS custom taxonomy.

While this has been a very brief introduction to custom taxonomies I hope you get an understanding of what they can do and their potential for helping you organise the posts on your site. To go deep into custom taxonomies I recommend this article at Smashing Magazine.

Plugins to Create Custom Post Types and Taxonomies

While creating custom post types and taxonomies requires adding code to the WordPress functions.php file, it is possible to create them using a plugin which takes all the coding out of the task.

For the examples on this page I used the free WCK Custom Fields and Custom Post Types Creator plugin which lets you create custom post types, meta boxes and taxonomies from within the WordPress admin.  Custom Post Type UI looks like another good custom post types plugin and is very popular at WordPress.org with over 250,000 downloads so far.

When it comes to premium WordPress plugins for creating custom post types and taxonomies there are a few options out there:

  • WordPress Content Types Generator: helps you create post types, taxonomies, meta boxes and meta fields as well as providing you with video tutorials to quickly get you up to speed with working with this kind of functionality in WordPress. This plugin also lets you export the code for use on other WordPress site even if they don’t have this plugin installed making it a good choice for developers.
  • WordPress Content Types Manager: create unlimited post types without editing any code as well as creating custom shortcodes and custom theme options such as colour pickers and image sliders.
  • Easy Content Types: simplifies the whole process of creating custom post types and associated features as well as set the user access control to determine who can create post types, taxonomies and met boxes.

While creating your own custom post types by hand can be a rewarding and educational experience, using these plugins allows anyone to get started with them in a very short time and begin cataloguing and indexing their content in much more efficient ways than is possible with the standard WordPress post type and only the choice of using categories and tags.