How to Create And Handle Custom Post Type

customposttype-sidebarCustom Post Type was introduced in WordPress 3.0 to allow the users to define different post type within a blog. For example, if you are a chef looking to open new cooking classes and also to share your recipes with others, you can define a post type call “Classes” where you announce the availability of new cooking class and another post type call “Recipe” and share your recipe with your readers.

WordPress doesn’t come with an easy way for the normal users to create custom post type, but luckily there is a useful plugin for that.

Custom Post Type UI is a WordPress plugin that allows you to create custom post type with a few clicks. It is pretty comprehensive and easy to use.

After installing (and activating) Custom Post Type UI, go to “Custom Post Tpe -> Add New“.

customposttype-main

On the left side is where you create custom Post Type and the right side is where you create custom taxonomies for the custom post type.

To create a new custom post type, fill in the detail on the left pane and click “Create Custom Post Type”.

customposttype-new-post-type

You can also click on the Advanced Options to see more configuration options.

customposttype-advanced

Here is where you can change the permalink structure for your custom post type and also define what features it support. To get full capabilities, the best way is to check all the boxes beside the “Support” field.

Adding Categories and Post Tags feature to Custom Post Type

After we have added a new custom post type, we want to set up the categories and post tags feature for this post type. While we can reuse the existing categories and post type, it will cause an overlap with the default post structure.

Select the Post Type that this is attached to (the post type that you have just created).

customposttype-taxomonies

To create a new custom taxomonies, fill in the detail on the right pane (Create Custom Taxomonies). Under the Advanced option, for Category-type feature, select “TRUE” for “Hierarchical”. For Post Tags feature, select “FALSE”.

When you are done, you should now see a new entry in your sidebar.

customposttype-sidebar

You can now insert new Cooking Class or Recipe as per normal post.

Viewing custom post type on the frontend

In most cases, WordPress will load the custom post type with URL of the form: http://your-site-url.com/post-type-rewrite-slug/your-permalink-structure.

The “post-type-rewrite-slug” is the “Custom Rewrite Slug” that you have set when creating the custom post type.

However, some of you might see a “404 not found” page instead. This is because WordPress has not registered the permalink structure of the Custom Post Type yet. To fix this, in the Dashboard, go to “Settings -> Permalink“. Click the “Save Changes” button without changing anything. This will flush the permalink structure and register the custom post type rewrite slug.

Now, you should be able to view your custom post type on the frontend.

  • Anjali

    Nice tutorial. i am also working on wordpress for last year .. good collection of wp bits.