How to create custom post type with taxonomy in WordPress

In this post, I am going to explain how to create custom post type with category/taxonomy in WordPress without any plugin.

There are lots of plugin available for custom post type and taxonomy but if you want to create without any  plugin,then needs to follow given steps.

You can create custom post in two ways first use  below code in your active theme functions.php file or create new own plugin and paste below code in your plugin file.

Example:-




Now save file and check in admin new post type book is registered. you can create lots of custom post according to need using register_post_type(‘post_type_name’,$args); function.
This function takes two parameters first post type name and second array type.

Now for category/taxonomy WordPress provided predefined function register_taxonomy( ‘book-category’, array( ‘book’ ), $args ); 

This function adds or overwrites a taxonomy. It takes in a name, an object name that it affects, and an array of parameters. It does not return anything.

Example:- Please copy the below code and paste it in your active theme functions.php file.

If you want create multiple categories for single post then you can create lots of category there are no restriction in WordPress you can create lots of category like author,publication etc.

custom taxonomy/category

 

12 Comments

Add a Comment

Your email address will not be published. Required fields are marked *