Creating a Custom Post Type

A power house feature of WordPress is custom post types. When a page, or a post is just too basic for the content needed WordPress allows the creation of a custom post type. In this article we are going to look at the creation of a custom post type in WordPress, I’ll follow that up with adding custom fields to? post types, and then we’ll wrap it all up by showing how to output it all for users to enjoy.

Post Type Creation Tools

There are several tools available to create post types from within the dashboard area itself, here are a few of them and the pros and cons of each.

Custom Post Type UI

Custom Post Type UI is a very clean, very simple to use plugin. It adds a new admin section to WordPress where you can go in and feel out a simple form to create post types and taxonomies. Its very straight forward and very simple to use. The only real con with it is you have to code your output in your themes templates unless you use their premium plugin Custom Post Type UI Extended.

Pods

Pods?like Custom Post Type UI allows users to create post types and taxonomies but it goes one step further and allows the creation of custom fields, all from within the WordPress admin. It has more features than can be listed in this post, but I’ll do a full review of it in a feature post. Overall though it comes with a bit more features than Custom Post Type UI, but with that said it can give you a bit more than you may need to create a basic post type.

Toolset Types

When I first began my career with WordPress I did a lot of work with Toolset Types and it taught me quite a bit about how to work with post types. Like the above mentioned plugins it also gives users the ability to create custom post types, fields, and taxonomies it goes a step further with its premium plugin, Views by allowing you to create the output of the custom content within the admin area and without having to know any php. I believe its a good plugin set to start out with to kind of get comfortable with post types. The downside is its a very large plugin, and without updating some settings adds a lot of clutter in different areas of your site.

Post Type Code

A plugin from the repo or a premium plugin is not needed to create a custom post type, it can be done with just a few lines of code. If you decide to go this route the first question you will ask is where to put the code. Some situations may call for a post type to be in a theme, but generally speaking you will usually want to put your post type code in a plugin, it can be a standard plugin or in an mu-plugin but either way it should probably be in a plugin. The benefit of adding a custom post type to a plugin would be a user can switch themes without deactivating their post type and they can still edit the content of it. With that said lets dive into some code!

You can find documentation for this on the WordPress codex here.

Wrapping Up

Tools like Custom Post Type UI, Pods, and Toolset Types make it super simple to create post types from within the admin, with tools like that you do run the risk of a client stumbling into the settings and breaking things on the site if some proper steps aren’t put into place. I prefer to create my posts in a functionality plugin, and the best thing I can refer you to on that is the codex link above. Study study study the WordPress docs if you’re going to code your own post type and it will make your life much easier.