WordPress Event Ticketing

The Ultimate Guide To Post Types

Post Types are one of the core aspects of WordPress. Nearly everything you do in WordPress revolves around a post type. There are, though, common misconceptions and confusion around many elements of a post type. One being that users, newer to the community, believe that Post Types are only Posts. In this guide, you'll learn what Post Types are and how you can use them to create your own custom WordPress site.

 

What Are Post Types?

Post Type is the term in WordPress to refer to different content types. Initially, WordPress was launched primarily as a blogging platform. When this was expanded on, and more content types were added the name "Post Types" stuck. With the introduction of attachments, pages and posts and taxonomies WordPress became a content management system (CMS) and was no longer just focused on the blogging aspects.

Not sure what is Tickera? Go here to find out!

Developers can register their own post types allowing WordPress to be extended beyond the core post type set which is covered below.

Out of the box WordPress has these post types by default:

  • Post (Post Type: 'post')
  • Page (Post Type: 'page')
  • Attachment (Post Type: 'attachment')
  • Revision (Post Type: 'revision')
  • Navigation Menu (Post Type: 'nav_menu_item')
  • Custom CSS (Post Type: 'custom_css')
  • Changesets (Post Type: 'customize_changeset')

The official WordPress Codex has a great explanation of these different post types and how exactly they work here.

 

The Power Of Post Types

Post Types are an incredibly powerful piece of functionality within WordPress. Many plugins you use will register their own post types and create completely custom outputs using post types. Post types can be ordered in a myriad of ways allowing for custom loops and displays in themes. The most popular WordPress plugin WooCommerce uses a custom post type as do thousands of others.

Anyone can register or modify a post type using the register_post_type function which is explored in-depthly here.

If you don't want to code your own custom post types and display templates there are plugins that can do this out the box for you, one of the most popular being a plugin called Toolset developed by the same people who created WPML. Toolset is an incredibly powerful plugin that allows you to create custom post types, custom fields, and custom taxonomies all within an easy to use admin interface then create templates without a single line of code!

 

Custom Fields

Custom Fields can be added to any post type within WordPress. This information is technically known as meta-data and can be used within your custom templates to display any information you want. And, as you guessed, some of your favorite plugins already make use of Custom Fields and just like with Post Types, Toolset works great with custom fields.

 

There's an extremely popular plugin worth mentioning which is called Advanced Custom Fields, commonly referred to as  ACF.

 

ACF allows you to create custom fields and field groups all from within an easy to use admin interface. It is slightly more complex as you'll need to output the field data using either shortcodes or a generated PHP snippet in your templates. Because of this it's a powerful tool for developers, and ACF Pro includes even more advanced functionality.

 

Custom Taxonomies

Taxonomies are another component of post types and are explained fully in the WordPress Codex. The simplest way of explaining taxonomies is that they're used to group various posts and data together in WordPress. For example a default taxonomy is Category. You can then add different categories to your WordPress site allowing you to group your posts together in that specific category.

 

Pitfalls

While there are no major pitfalls with post types the main issue to watch out for is copying code you find to register a custom post type and creating a post type with a normal name. For example, if you create a post type called "product" that could conflict with another plugin that uses the "product" post type meaning that data you don't expect shows up in the other plugin.

 

Custom Post Types In Themes

There is a question of whether themes should include custom post types or not. It's generally seen as themes should provide a design and templates while plugins provide the functionality such as post types. However the use of custom post types within themes is becoming increasingly common. One of the main use cases is themes that include Portfolio functionality and register a portfolio post type commonly prefixed with the theme name. This allows you to have a completely custom portfolio out the box.

Some developers would say this is something that shouldn't be done and others will say there's no problem with such development.

While I'm usually on the side of the former, for something like a portfolio, this wouldn't really be a problem. It's a more generalized post type and if you have an online portfolio chances are you'll be sticking to the same theme and if you don't want to a plugin could always take its place. An exception would be if a theme created a completely custom eCommerce store for you and tied you in. That type of functionality should always be left to a plugin such as Easy Digital Downloads or WooCommerce.

 

Conclusion

Post Types are very powerful and important part of WordPress. Without them, you wouldn't have some of the much-loved functionality, and many plugins wouldn't exist. As with everything, you should create custom post types only when you need them and not end up with hundreds on your install. Have you used Custom Post Types? Ever had an issue with conflicting Post Type names? Let us know in the comments below.

Leave Us A Message!