The Complete Guide to WordPress Custom Post Types

Most bloggers don’t use WordPress custom post types because they don’t know what are WordPress custom post types and what type of advantages it has.

WordPress isn’t just a blogging platform. You can made an awesome websites using WordPress. Most WordPress developers use WordPress custom post types , taxonomy and WordPress custom fields to build such sites.

I will write a post about WordPress custom fields in near future. Today, I share a complete guide about WordPress custom post types.

What is Custom Post Types in WordPress?

There are five post types comes with default WordPress installation.

  • Post : Post is a most used post type in WordPress. You call it as a blog post.
  • Page : You know the page type also. You use page type when you creating static page like contact us page, privacy policy page.
  • Attachment : All the media files like images, PDF stored as attachment type in WordPress.
  • Revision : The draft post saved as revision post type.
  • Menu :  Menu type store the information about a single item in the WordPress navigation menu system.

Above types are the default post types. WordPress custom post types is a type which you can create for your WordPress site.

I will give an example for WordPress custom post type using my blog. I wanted  to add a infographic directory for my blog.

I had two option to publish infographics on my blog.

  • As blog posts : I thought it isn’t a good option because it may be annoyed for readers because some readers don’t like infographics. As well as it may decrease the RSS subscribes because Myself and other users may add two, three infographics per day and it will be annoyed for RSS subscribes.
  • As pages : It is also not a good option because it is hard  to set a structure. Blog readers can’t check infographic easily without a structure. As well as it is hard to categories infographics because pages doesn’t support for categories or tags.

Then. I searched a solution. I found the WordPress custom post type.

Check out the infographic directory on this blog to get an idea about WordPress custom post types. It is created by WordPress custom post type called infographic.

When Do You Need a Custom Post Type

You may need WordPress custom post types for several reasons.

  • To separate some posts from main posts: As I wanted to separate infographics from my main blog posts, you may also want to do something like that.
  • Categories and tags don’t help you to sort some posts:  For an example, take a film. You need to sort films as title, director, country, etc. You can use WordPress custom post types with taxonomy to do it.
  • For some special posts : You can use WordPress custom post types for some special posts like discount coupons posts.

 How to Create WordPress Custom Post Types?

There are two ways to create WordPress custom post type.

1. Using Codes

You can add a function to create it. This is a basic example.


add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'acme_product',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
),
'public' => true,
'has_archive' => true,
)
);
}

You can learn more about this from WordPress Codex.

2. Using a WordPress Plugin

If you don’t have a good knowledge about WordPress development you can use a WordPress plugin to create custom post types in WordPress.

I have mentioned a plugin called Custom Post Type UI in best WordPress plugins post.

It is easy to use this plugin because you don’t need any WordPress development knowledge.

This is a good video tutorial about using this plugin to create custom post types. This video is created by WpBeginner.

How to Add WordPress Custom Post Types to Main RSS Feed?

You may want to add custom post types to main RSS feed. It isn’t hard. You need to add following code to functions.php page.


function add_feed_to_main($abp) {

<span style="line-height: 1.5;">if (isset($abp['feed']))</span>

$abp['post_type'] = get_post_types();
return $abp;
}
add_filter('feedtomain', 'add_feed_to_main');

Above code will  add all custom posts feed to main RSS feed.

What is a Taxonomy and When do you need it?

Category and tag are examples for taxonomies.

Some type of posts may be needed sort by many things. You can use taxonomy for that type of requirements. You can add taxonomies for blog posts also. But most of the time taxonomies are used with custom post type. You can use Custom Post Type UI  plugin to create taxonomy also.

If you need to do it manually this is a basic example.

function people_init() {
	// create a new taxonomy
	register_taxonomy(
		'people',
		'post',
		array(
			'label' =&gt; __( 'People' ),
			'rewrite' =&gt; array( 'slug' =&gt; 'person' ),
			'capabilities' =&gt; array(
				'assign_terms' =&gt; 'edit_guides',
				'edit_terms' =&gt; 'publish_guides'
			)
		)
	);
}
add_action( 'init', 'people_init' );</pre>

You can learn more about taxonomies from WordPress Codex taxonomy page.

WordPress Custom Post Type Guides

I used so many guides to learn about WordPress custom post types. I will share some of them.

1. A guide to WordPress custom post types : You can find two tutorials from this link.  All two articles written by Soumitra Chakraborty for Tutsplus.

A guide to WordPress custom post types

2. Create your first WordPress Custom Post Type : This is also good guide to learn how to create WordPress custom post types.

Create your first WordPress Custom Post Type

Conclusion

You can find more tutorials about WordPress custom post types on YouTube and WordPress tutorial blogs. Use this awesome feature to give the better experience for your readers. If you are a creative person, you can add unique parts for your blog using custom post types.

Post Comment