Using and Extending WordPress Content Types

by | Feb 12, 2015 | Web Development

Magic through information architecture


Whether you’re developing a WordPress plugin/theme or you’re looking for someone to develop one with you, understanding how WordPress handles it’s content is key. The most important aspects are taxonomy and posts. Posts and Pages and Categories and Blogs are easily understandable concepts on their own but leveraging their unique characteristics, and knowing where their shortcomings lie, can help anyone looking at WordPress as a development or publishing platform.

Everything is a Post, Everything is a Taxonomy


When WordPress is first installed it comes with Posts, Pages, Categories, and Tags. Each of these are indicative of how content is managed in WordPress, starting with the Posts portion of WordPress’ content:

  • Posts – traditionally sequential by date, and used for time sensitive information, such as blogs or newsletter archives. Posts are independent, they cannot have child or parent posts, however they can have Categories and Tags associated to them. Posts have a single template for every post, it cannot be changed.
  • Pages – hierarchical posts not used for time sensitive information. Pages typically are not changed often. Pages can have child and parent pages, though they typically do not have Categories or Tags associated with them. Pages can also have custom templates applied to each one to change how they look.

In short: Posts and Pages are just posts with different attributes and use cases, this will be very important after we go over taxonomy. Posts work best in blogs and dynamic streams of information, whereas Pages work best for “pages” of your site that will be static; pages are what you would use in your menu, for example.

Much like the two post types, Posts and Pages, that come with WordPress, WordPress also comes packaged with two taxonomies: Categories and Tags. Taxonomies are for organizing your posts and pages.

  • Categories – hierarchical organization. Categories can have parent and child categories applied to them and can be used to sort and search posts by that hierarchy. Categories are usually umbrella terms that a post can be described by.
  • Tags – non-hierarchical organization. Tags cannot have parent or child tags applied to them and are used for granular terms that can describe a post.

An example of Categories could be Toyota->Camry. Toyota is the parent category, whereas Camry is the child category. Both are broad enough to describe the post, and Camry would be related to Toyota. On the other hand, some tags that same post could have the tags: tires and windows. Tires and windows on their own are too fine to be used as categories compared to Toyota and Camry, but due to post’s content tagging the post with tires and windows would make searching for this particular post much easier for users and for the editors of your WordPress site.

But I want more!


So in short review: WordPress comes with two post types (posts and pages) and two taxonomies (categories and tags); but what if your needs go beyond just those? What if, for example, you wanted to be able to manage Events in WordPress? Enter custom post types and custom taxonomies. While WordPress comes with some pre-packaged goodies that suit most needs, custom post types and custom taxonomies can fill the need for more specific situations. Let’s take our Events a little further to see how WordPress can help us make that happen. For our Events we want to be able to categorize them, but we don’t want to use WordPress’ built in Categories because we also have a blog going; we just need Events and Event Categories. No problem, with WordPress’ Actions & Hooks API we can register a whole new post type called events as well as a whole new custom taxonomy called event categories that is only accessible to events. With those created we can look back at what post types and taxonomies our WordPress site has available to us:

  • Posts
  • Pages
  • Categories
  • Tags
  • Events
  • Event Categories

For the technically inclined, you can just as register post types and taxonomies as so in your functions.php file or wherever you are handling WordPress functions:

Register Post Type



function register_events_posttype(){
  //Labels used in the WordPress Dashboard
  $labels = array(
    'name'               => _x( 'Events' ),
    'singular_name'      => _x( 'Event' ),
    'menu_name'          => _x( 'Events' ),
    'name_admin_bar'     => _x( 'Event' ),
    'add_new'            => _x( 'Add New' ),
    'add_new_item'       => __( 'Add New Event' ),
    'new_item'           => __( 'New Event' ),
    'edit_item'          => __( 'Edit Event' ),
    'view_item'          => __( 'View Event' ),
    'all_items'          => __( 'All Events' ),
    'search_items'       => __( 'Search Events' ),
    'parent_item_colon'  => __( 'Parent Events:' ),
    'not_found'          => __( 'No events found.' ),
    'not_found_in_trash' => __( 'No events found in Trash.' )
  );

  //Post type attributes
  $args = array(
    'labels'             => $labels,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'events' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
  );

  //Register our post type for use in WordPress
  register_post_type( 'event', $args );
}

Register Taxonomy



function register_event_categories(){
  // Add new taxonomy, make it hierarchical (like categories)
  $labels = array(
    'name'              => _x( 'Event Categories' ),
    'singular_name'     => _x( 'Event Category' ),
    'search_items'      => __( 'Search Event Categories' ),
    'all_items'         => __( 'All Event Categories' ),
    'parent_item'       => __( 'Parent Event Category' ),
    'parent_item_colon' => __( 'Parent Event Category:' ),
    'edit_item'         => __( 'Edit Event Category' ),
    'update_item'       => __( 'Update Event Category' ),
    'add_new_item'      => __( 'Add New Event Category' ),
    'new_item_name'     => __( 'New Event Category Name' ),
    'menu_name'         => __( 'Event Category' ),
  );

  //Taxonomy Attributes
  $args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'event_categories' ),
  );

  //Register our taxonomy. The second attribute, array('event'), defines what
  //post type the taxonomy should belong to.
  register_taxonomy( 'event_category', array( 'event' ), $args );
}

*Check out the Codex for more info about custom post types and custom taxonomies if you are so inclined. By registering and associating custom post types and custom taxonomies you can greatly extend the functionality of WordPress not just from a developmental point of view, but also from a content structure point of view. By sectioning off content into particular sections on your WordPress’ Dashboard through post types, you extend that organization to the front-end as well and it will show to your users.

One thing you’ll notice if you’re using the Divi Builder by Elegant Themes is that you can’t use the blog templates functionality in the same way you do with the native WordPress plugins like Pods or Custom Post Types UI. If you’re using Divi and want to make your custom blog/page template work on custom post types beyond Projects and Posts in WordPress, you can learn how to do that by checking out this article.

Content Management Guru


When planning a new WordPress plugin or theme, keep in mind what you want to get out of it and how your content will translate to WordPress’ post and taxonomy structures. Separating types of content early on will help you and your developers understand the technical aspects from a holistic point of view. It’s the WordPress equivalent of not forcing a square peg into a circular hole: sure you could have everything as a page and create complicated internal rules for organization, but that will reflect to your users and, just as importantly, it will effect the SEO of your site as well. Easily traversable and cleanly organized content goes a long way for SEO and your users.

Share This