An Intro to Custom Post Types, Taxonomies, and Fields

Hello everyone, and welcome to the first of many posts explaining the real core of what powers WordPress, and how you can use it to the greatest effect.

In this (hopefully quick and clear) overview, we’re going to explore a few basic WordPress concepts to set the foundation moving forward. Let’s jump right in!

Note: This post won’t discuss how to make Post Types, Taxonomies, and Fields, but their overall structure. The technical how-to can be found in the Codex, and is coming in later installments. 🙂

The Custom Post Whats?

Post Types, Taxonomies, and Fields are things that every WordPress user takes advantage of, whether or not they realize it. If we fire up a fresh installation of WooCommerce, we’ve already got the basics set up – here’s an example of a few:

  • Post (Post Type) – Used for dated updates and blog articles.
    • Category (Taxonomy: Hierarchical) – Used to sort posts into groups by topic. A hierarchical taxonomy means items can be sorted into parent folders – for example, you could have Clothes, then Clothes > T-Shirts, Clothes > Pants, etc.
    • Tags (Taxonomy: Non-Hierarchial) – Used to identify important keywords that may not warrant their own section of the blog, but could be important search terms. These can not be stacked, so are more appropriately used for descriptive keywords, like color, size, brand, etc.
      • Post Title (Post Field) – The title of the post
      • Post Content (Post Field) – The article content
      • Featured Image (Post Field) – An image or thumbnail for your post
  • Page (Post Type) – Used for static content that isn’t date specific like “About Us” pages.
    • Same taxonomies as above (meaning a search for a certain keyword or taxonomy term will return results from BOTH post types, if enabled).

We’re cooking already and have some options set up for us. It’s important to remember the two (and a half) basic post types – Post and Page (both Hierarchical and Non-Hierarchial).

What Are Custom Post Types?

Custom Post Types are a feature in WordPress that allow you to add a whole new section to your site – say you wanted to list your employees, with bios, images, and contact information for each of them.

Previously, to keep this information separate you had two choices – either to hard-code the information into a page (meaning that any updates would have to be done by hand and in HTML) or to use a taxonomy tag and special filter to display the content. This proved to be a big pain to manage in the backend, and users needed a way to cleanly divide information – thus, the Custom Post Type was born.

When creating a custom post type, it’s important to think of how your content will be displayed. To make it easy, here’s a quick flowchart to help you figure it out:

flowchart

The possibilities are really endless in what you can use Custom Post Types for, but some of the most common examples are:

  • “Our Team” bios
  • Customer testimonials
  • Calendar Events
  • Product and Service Pages

Custom Post Types also inherit the same template capabilities as Posts and Pages, meaning you can add custom layouts specific to a Post Type into your theme.

What are Custom Post Taxonomies?

Custom Post Taxonomies (or simply Taxonomies) fill the same role as the “Category” and “Tag” groups mentioned before – they’re used to sort your content. You can have as many taxonomies per Post Type as you’d like, and you can even allow post types to share a taxonomy. This is a flexible tool but hard to explain – we’ll come back to it in a second.

What are Custom Post Fields?

Custom Post Fields are just as they sound – custom data fields that can appear on one or many custom post types. This information is written and saved to the database alongside the main content and title, and comes in many forms. This can be a whole article on its own, but know that they simply allow you to create customized fields to fill in per post type.

Putting It Together – A Demo Site

This may be a lot to take in at first, and I personally prefer to learn from real-life examples, so let’s create a sample scenario and assign post types and taxonomies.

The Client Profile

Hooray! We’ve been contacted by a reputable client (you know, the white whales who pay on time) to completely revamp their website. Here are some specifications and requirements sent to us by the client, Cyberdyne Systems:

  • Cyberdyne Systems designs and builds high-end computer components, security software, and defense hardware.
  • They would like to have a single catalog that lists all of their products and services so a customer can search and find anything they produce in one location.
  • To keep customers informed and improve SEO, they need three separate blog feeds, one for computers, one for security, and one for defense hardware.
    • In certain cases such as new product releases, software updates, or recalls, they want to be able to link a product to the post.

Tall order, right? Luckily, we can pretty easily break it all down into manageable chunks. You’re likely familiar with the basic WordPress backend – while this could certainly do the job, we want the sections to be perfectly clear to the user.

The Comfy Dashboard. Stylish, but not exactly what we need.

Creating Custom Post Types

For the sake of organization, we want to keep the different feeds in entirely separate areas in the backend. Therefore, we’ll create three custom post types for the feed:

  • Computers
  • Security
  • Defense

In addition, we’ll want a post type where they can put all of their products, so a fourth post type can be created called “Products” (or, just download WooCommerce and let it handle this part for you).

This leaves us with the following Post Types with specific uses:

  1. Posts – Used for company-wide announcements such as stock news, new hires, or job offerings
  2. Pages – Used for static information like contact pages, About Us, etc.
  3. Computers – Used for blog articles related to computers
  4. Security – Used for blog articles related to security
  5. Defense – Used for blog articles related to defense
  6. Products – Used to list all products and services offered (in a catalog-style feature)

Now, our wp-admin looks familiar, but with additional options for our end user:

Admin with Custom Post Types

Creating Custom Post Fields

For the most part, we can leave the three blog articles alone – Categories and Tags are effective enough to sort most news feeds. However, we’ll definitely need to modify the Products Custom Post Type – that’s where Custom Fields come in. By default, we have a title, description, and image field – let’s add the following Product fields:

  • Product SKU
  • Price
  • Availability

For demonstration (and as a general recommendation should you ever need to sell online), I used a quick WooCommerce setup to achieve this. Zero code? I’ll take it.

Connecting the Post Types through a Taxonomy

To take things a step further, we want to add a taxonomy – Product Line. This allows us to differentiate between different types of software, computer parts, etc. Since we want to be able to link blog posts to articles, we’ll extend that Taxonomy and allow it to appear on our three custom feeds.

categories

Clean, Legitimate, and Totally Not Evil.

The Final Result

What we’ve done is created an effective, organized system with just a few tweaks and additions, all using simple code snippets you can get from a generator.

A Little Lost? Don’t worry! It can be hard to grasp off the bat, which is why I’ve set up a demo site using the exact specifications discussed. You can see the one-day, ultra-fast mockup in action here:

CyberDyne Systems Online

Next Steps

Congratulations! We’ve gotten through the base concepts of what makes WordPress go. Armed with this information (and a few T-101s), we can start to see the real potential of WordPress. Stay tuned for further installments!


Have any questions or comments about this article, or ways you think it can be improved?
Join the conversation in the comments below, or sign up for my newsletter to recieve periodic updates!

Tags: , , , ,

No comments yet.

Leave a Reply

%d bloggers like this: