Stay connected

How to Create a Custom Post Type WordPress

In WordPress version 3.0, custom post types were displayed. Developers can conveniently include various content types to the themes and plugins and increase the capability of WordPress, making it somewhat similar to a thorough Content Management System.

What exactly are these custom post types?

Simply put, a custom post type represents a particular content type. You should not get puzzled by the term “post” in the title. It may mean anything you would like to represent. The various types of default post associated are

Pages

posts

Revisions

Attachments

New Menus

You can understand that through the custom post type, you can change the content in a similar way wherein you would do for a blog. In fact you will have more control on how the content is shown. If you just want to differentiate the content in various ways, you may think of doing it with tags, custom taxonomies and categories.

Creation of a custom post type

To create a custom post type is relatively easy and you will be surprised to see how WordPress really works. As you start working with it, you will understand its capacity. You have to include in the functions theme’s .php file, the given code.

This is what you have to do for creating a custom post type. For creating a “book” custom post type which can be used to make a database of books, some labels are given, few options are set, and that is all.

The given example is simple but shows how simple things can be created using the custom post types. Now visit the WordPress admin panel, to find out “books”. You can explore with the new “books”.

To create a book database

The “Wordpress Codex” explains how to create custom post type and also set them with the given options. There is a helper function which allows you to bring out labels which are used for custom post type in WordPress admin. There is an option to set the $ label manually as well.

Lastly you can add a filter to alter the messages that are updated. WordPress shows right labels, whenever a message is updated for a particular custom post type.