How to create Custom Taxonomy in WordPress?

How to create Custom Taxonomy in wordpress?

What is Taxonomy in WordPress??

Basically, a taxonomy in WordPress, is a group of data (say pages or post in our case) which are having same nature or same kind of features that are sharing.

For example, Our custom pages are having some post or data of different type like tour post, travel diary, recipes or programming suggestion. Now we can group them together according to various characteristics they are having and then assign those groups names. We have listen this words in our biology classes seems technical but interesting, and it is known as the Linnaean Taxonomy.

WordPress taxonomies are used to group posts and custom post types both together. WordPress is having five built-in taxonomy.Built in taxonomy are Category,Tag,Link Category,Post Formats. Among them two are very popular that every WordPress user are using. that are categories and tags. other than this many time we need to create as per our requirement that are called as the custom taxonomy.This will help us to keep our custom post type’s post which are sharing same features. For example, we are having a custom post type named Programming. We are not using the post hence the categories will not fit in our case. So now we have to register a new custom taxonomy called as programming_type. We can add terms like: designing, programming, animation, etc. This will allow us and our users to bifurcate our programming post by its special characteristic. Taxonomies can be hierarchical means, we can have our terms like: WordPress, java, and Asp.Net. Then have subtopics under each category for example java would have oops concept as a sub-topic.

How to Create Custom Taxonomy in WordPress?

Let’s see how to create custom taxonomies in WordPress. We are having two possible ways to create custom taxonomy. Method 1 would utilize a plugin for the people who do not want to do code or unaware about coding. In method 2 we will create the custom taxonomy manually.

Step 1: Creating the Custom Taxonomy in WordPress Using Plugin

If the person is not aware about coding and where to code than this method will be perfect for them, even also suites to the developers who are working on Rapid Application Development.

We need to download plugin from the WordPress plugin Repository. There are lots of plugin available for this but i personally prefer Custom Post Type UI by WebDev Studio. This will be helpful in creating the custom post Type and also the taxonomy. We are familiar that how to install a Plugin in WordPress Website. Once the installation is done and the plugin is active we need to go to CPT UI » Add/Edit Taxonomies. Once open We need to fill the requested details like Taxonomy Slug, Plural Label, Singular Label and check Post type names on which we need to bind the taxonomy. Other Labels Can Be given to it in the text input box at the right side.

Wordpress-CPT-UI-custom-taxonomy

Other than this details we can also fill the details available as the setting .

  • Hierarchical : This will allow the taxonomy to have the children or say sub-categories.
  • Show UI : This can be true or false, this will create a default User Interface for managing this taxonomy.
  • Query Var : This is used for direct queries through WP_Query it can be true or false.
  • Custom Query Var String : the new string using which we search in WP_Query this need Query Var true.
  • Rewrite : Weather we want to rewrite the slug or not, this can be true or false. if we make true than next 4 will work.
  • Rewrite Slug : This will rewrite the slug and make the permalink attractive.
  • Rewrite with Front : this will allow permalinks to get prefixed with front base
  • Rewrite with Hierarchical : this will allow permalink to be hierarchical.
  • Show Admin Column : this will allow to show in the admin column.

Wordpress-CPT-UI-custom-taxonomy-other-settings

Once we are done filling this details we get our taxonomy created and assign to the our checked post types. this can be shown on the multiple post type.

Newly Created Custom Taxonomy

Step 2: Creating the Custom Taxonomy in WordPress in Manual way.

The other way to create the custom taxonomy in WordPress is creating it manually. this is not easy task but if you are clear that what you want to do and where to put this code than this will be most easy to perform the above way using plugin is very easy and very quick to implement hence its preferable but not advisable. i personally make every thing using the code. so in order to create this using code we have to be familiar with register_taxonomy() this will allow us to create the Custom Taxonomy in WordPress.

Lets have The above example again, we need to create a taxonomy named as ‘Article’.

// Register Custom Taxonomy
function custom_taxonomy() {

	$labels = array(
		'name'                       => _x( 'Articles', 'Article General Name', 'theme_domain' ),
		'singular_name'              => _x( 'Article', 'Article Singular Name', 'theme_domain' ),
		'menu_name'                  => __( 'Article', 'theme_domain' ),
		'all_items'                  => __( 'All Items', 'theme_domain' ),
		'parent_item'                => __( 'Parent Item', 'theme_domain' ),
		'parent_item_colon'          => __( 'Parent Item:', 'theme_domain' ),
		'new_item_name'              => __( 'New Item Name', 'theme_domain' ),
		'add_new_item'               => __( 'Add New Item', 'theme_domain' ),
		'edit_item'                  => __( 'Edit Item', 'theme_domain' ),
		'update_item'                => __( 'Update Item', 'theme_domain' ),
		'view_item'                  => __( 'View Item', 'theme_domain' ),
		'separate_items_with_commas' => __( 'Separate items with commas', 'theme_domain' ),
		'add_or_remove_items'        => __( 'Add or remove items', 'theme_domain' ),
		'choose_from_most_used'      => __( 'Choose from the most used', 'theme_domain' ),
		'popular_items'              => __( 'Popular Items', 'theme_domain' ),
		'search_items'               => __( 'Search Items', 'theme_domain' ),
		'not_found'                  => __( 'Not Found', 'theme_domain' ),
		'no_terms'                   => __( 'No items', 'theme_domain' ),
		'items_list'                 => __( 'Items list', 'theme_domain' ),
		'items_list_navigation'      => __( 'Items list navigation', 'theme_domain' ),
	);
	$args = array(
		'labels'                     => $labels,
		'hierarchical'               => false,
		'public'                     => true,
		'show_ui'                    => true,
		'show_admin_column'          => true,
		'show_in_nav_menus'          => true,
		'show_tagcloud'              => true,
	);
	register_taxonomy( 'taxonomy', array( 'post' ), $args );

}
add_action( 'init', 'custom_taxonomy', 0 );

here we have made 'hierarchical' => false that means there will no child to the taxonomy terms just like the wordpres tags, but if we want to create child to taxonomy than we have to keep it true.'show_tagcloud' => true will allow the tagcloud widget to create the cloud of this custom taxonomy.

We need to create the above code in the functions.php of our theme or the file that is included in the functions.php so that this action will hook with init and create our taxonomy.
here we can manage the Capabilities of the taxonomy. You must wonder that what is capability and how to assign the capability. Capability are the rights given to the particular role. we can assign the four type of capability for the custom taxonomy in WordPress.

  • manage_terms: This capability will allow the user to Mange the terms.
  • edit_terms: This capability will allow the user to edit the terms.
  • delete_terms: This capability will allow the user to delete the terms.
  • assign_terms: This capability will allow the user to assign the terms to some post.

About Pashupatinath Mishra

Pashupatinath Mishra is Software Developer and our Fulltime blogger. He is having good knowledge on the Different Technologies and also having shareable knowledge on Nutrition, Science Topics, Travel and History.

Website

Summary
How to create Custom Taxonomy in WordPress?
Article Name
How to create Custom Taxonomy in WordPress?
Description
How to create the Custom Taxonomy in WordPress using the plugin of the WordPress and also manually.
Author
Publisher Name
Pashuaptinath Mishra
Publisher Logo

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.