Introducing Custom Posts and Taxonomies

This tutorial explains what WordPress custom post types and taxonomy are and how they work together to enrich WordPress.

Custom Post Types are a way of distinguishing different types of content on your WordPress website.

When you install WordPress you have two default content types:

  • Posts
  • Pages

Posts are the default content type that is used for blog posts. They are for dynamic content, with the first blog post displayed changing as a new one is added.

Pages are the default WordPress content type that is used for static content. Unlike posts these are not time-specific.

But Posts and Pages are not always enough. What if you want to create your own type of content?

WordPress makes this possible with Custom Post Types.

Note: The phrase “Custom Post Types”, though widely used by WordPress developers is misleading. A Custom Post Type is a not a “post” in the traditional sense that WordPress uses. Custom Content Type would be more accurate.

Custom Post Types are user defined and increase the flexibility of WordPress. You can create as many Custom Post Types as you want. Each Custom Post Type is a like a box that you put a specific type of content in. You’ll often find them being used in a variety of plugins – Products for eCommerce plugins, News for news plugins, for example.

Custom Post Type AutomotivePerhaps you have an automotive sales site and you want a method for posting the cars you have for sale. Posts and Pages aren’t adequate and, besides, you want to use them for your Posts and Pages. You need to keep each type of content separate.

With WordPress you can create your own Custom Type called “Automotive” enabling you to have a specific content type for vehicles. This keeps them clearly distinguished from your Posts and Pages. You can also customize the different types of data that are associated with your Automotive content. This could be information about price, age, registration. And we can classify our automotives into different groupings with taxonomies.

What are Taxonomies?

To the average user, “taxonomy” seems like an odd word to use. But let’s take a look at the definition on dictionary.com

  • the science or technique of classification.

Taxonomies are a way of classifying your content.

If you are already a WordPress user you have no doubt encountered the “Category” and “Tag” taxonomies.

Category is a hierarchical taxonomy. Its default term is “Uncategorized”. As you use WordPress you add more terms to the taxonomy, which you then use to categorize your blog posts. As this taxonomy is hierarchical you can create terms and child terms. Like so:
Category as a hierarchical taxonomy

Tags are non-hierarchical. This means there are no parents or children – anything goes! Just type in your terms when you create your post.

Tags as a non-hierarchical taxonomy

With Types you can create Custom Taxonomies, i.e. custom classifications your content.

Let’s return to our car example.

You have a Custom Type called “Automotive”, but there are lots of different forms of automotive out there. If you created Custom Post Types called “car”, “truck”, “motorcycle”, “buses” your site would soon become unwieldy. Instead you want to be able to group those that are similar together. Therefore, you create a taxonomy – vehicle. Within that taxonomy you define your terms. So:

Vehicle

  • Car
  • Bus
  • Truck
  • Motorcycle

You also want to be able to classify them by color, so you create a taxonomy “color”.

Color

  • Red
  • Blue
  • Green
  • Black
  • White

When you have created these custom taxonomies and associated them with your Custom Type, they will appear as options when a new piece of Automotive content is created.

Custom Taxonomies
Custom Post Types let you define a type of content.

Taxonomies classify that content.

Organizing your content in this way makes it easy for you, or your visitor, to search all of the automotive information and pull out the exact data that they want; a yellow sedan car, for example. There’s no limit to the number of Custom Post Types and Taxonomies that you can create.

Proper usage of Custom Post Types and Taxonomies take WordPress far beyond a basic CMS, letting designers and developers run wild with their imaginations.