How to Create Custom Taxonomies in WordPress – Website Tips

Curated by WorkingFromHome

This article is an excerpt from the original article found in the Read More link – please follow for full article.

Do you want to create custom taxonomies in WordPress?

By default, WordPress allows you to organize your content with categories and tags. But with custom taxonomies, you can further customize the way you sort your content.

In this article, we’ll show you how to easily create custom taxonomies in WordPress with or without using a plugin.

While creating custom taxonomies is powerful, there’s a lot to cover. To help you set this up properly, we have created an easy table of content below:

What is a WordPress Taxonomy?

A WordPress taxonomy is a way to organize groups of posts and custom post types. The word taxonomy comes from the biological classification method called Linnaean taxonomy.

By default, WordPress comes with two taxonomies called categories and tags. You can use them to organize your blog posts.

However, if you are using a custom post type, then categories and tags may not look suitable for all content types.

For instance, you can create a custom post type called ‘Books’ and sort it using a custom taxonomy called ‘topics’.

You can add topic terms like Adventure, Romance, Horror, and other book topics you want. This would allow you, and your readers to easily sort books by each topic.

Taxonomies can also be hierarchical, meaning that you can have main topics like Fiction and Nonfiction. Then you’d have subtopics under each category.

For example, Fiction would have Adventure, Romance, and Horror as sub-topics.

Now that you know what a custom taxonomy is, let’s learn how to create custom taxonomies in WordPress.

How to Create Custom Taxonomies in WordPress

We will use two methods to create custom taxonomies. First, we’ll use a plugin to create custom taxonomies.

For the second method, we’ll show you the code method, and how to use it to create your custom taxonomies without using a plugin.

Create Custom Taxonomies In WordPress (Video Tutorial)

If you prefer written instructions, then continue reading.

Creating Custom Taxonomies With A Plugin (The Easy Way)

First thing you need to do is install and activate the Custom Post Type UI plugin. For details, see our guide on how to install a WordPress plugin.

In this tutorial, we’ve already created a custom post type and called it ‘Books.’ So make sure you have a custom post type created before you begin creating your taxonomies.

Next, go to CPT UI » Add/Edit Taxonomies menu item in the WordPress admin area to create your first taxonomy.

On this screen, you will need to do the following:

  • Create your taxonomy slug (this will go in your URL)
  • Create the plural label
  • Create the singular label
  • Auto-populate labels

Your first step is to create a slug for the taxonomy. This slug is used in the URL and in WordPress search queries.

This can only contain letters and numbers, and it will automatically be converted to lowercase letters.

Next, you will fill in the plural and singular names for your custom taxonomy.

From there, you have the option to click on the link ‘Populate additional labels based on chosen labels’. If you do this, then the plugin will auto-fill in the rest of the label fields for you.

Now, scroll down to the ‘Additional Labels’ section. In this area, you can provide a description of your post type.

These labels are used in your WordPress dashboard when you’re editing and managing content for that particular custom taxonomy.

Next up, we have the settings option. In this area, you can set up different attributes for each taxonomy you create. Each option has a description detailing what it does.

In the screenshot above, you’ll see we chose to make this taxonomy hierarchical. This means our taxonomy ‘Subjects’ can have sub-topics. For instance, a subject called Fiction can have sub-topics like Fantasy, Thriller, Mystery, and more.

There are many other settings further down your screen in your WordPress dashboard, but you can leave them as-is for this tutorial.

You can now click on the ‘Add Taxonomy’ button at the bottom to save your custom taxonomy.

After that, go ahead and edit the post type associated with this taxonomy in the WordPress content editor to start using it.

Creating Custom Taxonomies Manually (with code)

This method requires you to add code to your WordPress website. If you have not done it before, then we recommend reading our guide on how to easily add code snippets in WordPress.

1. Creating a Hierarchical Taxonomy

Let’s start with a hierarchical taxonomy that works like categories and can have parent and child terms.

Add the following code in your theme’s functions.php file or in a site-specific plugin (recommended) to create a hierarchical custom taxonomy like categories:

  //hook into the init action and call create_book_taxonomies when it fires    add_action( 'init', 'create_subjects_hierarchical_taxonomy', 0 );    //create a custom taxonomy name it subjects for your posts    function create_subjects_hierarchical_taxonomy() {    // Add new taxonomy, make it hierarchical like categories  //first do the translations part for GUI      $labels = array(      'name' => _x( 'Subjects', 'taxonomy general name' ),      'singular_name' => _x( 'Subject', 'taxonomy singular name' ),      'search_items' =>  __( 'Search Subjects' ),      'all_items' => __( 'All Subjects' ),      'parent_item' => __( 'Parent Subject' ),      'parent_item_colon' => __( 'Parent Subject:' ),      'edit_item' => __( 'Edit Subject' ),       'update_item' => __( 'Update Subject' ),      'add_new_item' => __( 'Add New Subject' ),      'new_item_name' => __( 'New Subject Name' ),      'menu_name' => __( 'Subjects' ),    ); 	    // Now register the taxonomy    register_taxonomy('subjects',array('books'), array(      'hierarchical' => true,      'labels' => $labels,      'show_ui' => true,      'show_in_rest' => true,      'show_admin_column' => true,      'query_var' => true,      'rewrite' => array( 'slug' => 'subject' ),    ));    }  

Don’t forget to replace the taxonomy name and labels with your own taxonomy labels. You will also notice that this taxonomy is associated with the Books post type, you’ll need to change that to whatever post type you want to use it with.

2. Creating a Non-hierarchical Taxonomy

To create a non-hierarchical custom taxonomy like Tags, add this code in your theme’s functions.php or in a site-specific plugin:

  //hook into the init action and call create_topics_nonhierarchical_taxonomy when it fires    add_action( 'init', 'create_topics_nonhierarchical_taxonomy', 0 );    function create_topics_nonhierarchical_taxonomy() {    // Labels part for the GUI      $labels = array(      'name' => _x( 'Topics', 'taxonomy general name' ),      'singular_name' => _x( 'Topic', 'taxonomy singular name' ),      'search_items' =>  __( 'Search Topics' ),      'popular_items' => __( 'Popular Topics' ),      'all_items' => __( 'All Topics' ),      'parent_item' => null,      'parent_item_colon' => null,      'edit_item' => __( 'Edit Topic' ),       'update_item' => __( 'Update Topic' ),      'add_new_item' => __( 'Add New Topic' ),      'new_item_name' => __( 'New Topic Name' ),      'separate_items_with_commas' => __( 'Separate topics with commas' ),      'add_or_remove_items' => __( 'Add or remove topics' ),      'choose_from_most_used' => __( 'Choose from the most used topics' ),      'menu_name' => __( 'Topics' ),    );     // Now register the non-hierarchical taxonomy like tag      register_taxonomy('topics','books',array(      'hierarchical' => false,      'labels' => $labels,      'show_ui' => true,      'show_in_rest' => true,      'show_admin_column' => true,      'update_count_callback' => '_update_post_term_count',      'query_var' => true,      'rewrite' => array( 'slug' => 'topic' ),    ));  }    

Notice the difference between the 2 codes. Value for hierarchical argument is true for category-like taxonomy and false for tags-like taxonomies.

Also, in the labels array for non-hierarchical tags-like taxonomy, we have added null for parent_item and parent_item_colon arguments which means that nothing will be shown in

For the Full Article
You can Find it Here: How to Create Custom Taxonomies in WordPress

Commentary:
Quite intersting information and links can be read on this full article.
source – WPBeginner.com

You May Also Like…

How to Track Website Visitors to Your WordPress Site – Website Tips

How to Track Website Visitors to Your WordPress Site – Website Tips

Are you looking for an easy way to track your website visitors in WordPress? Tracking the number of website visitors on your site can help you get insights to grow your business. You can better understand your audience, look at which posts they like, where they come from, and how they use your website. In this article, we’ll show you how to easily track website visitors on your WordPress site (step by step). Why You Need to Track Your Website Visitors Tracking website traffic is one of the most important indicators of your website’s performance. More visitors means more opportunities for converting them into subscribers and customers. It also unlocks promising insights that you may have missed. For example, you can find out which country or city your visitors are from. This can help you deliver personalized content or figure out which languages you should translate your website in. You…

How to Fix WordPress Updating Failed / Publishing Failed Error – Website Tips

How to Fix WordPress Updating Failed / Publishing Failed Error – Website Tips

Are you trying to fix the WordPress updating failed or publishing failed error on your website? Sometimes when editing a post or page, you may see the updating failed or publishing failed error. This error does not give any clues, which makes it particularly difficult for beginners. In this article, we’ll show you how to easily fix the WordPress updating failed error. We’ll also explain what causes this issue, and how to avoid this in the future. What Causes Updating Failed or Publishing Failed Error in WordPress? Failure to communicate with the WordPress REST API causes the ‘Updating Failed’ or ‘Publishing Failed’ error in WordPress. Basically, WordPress sometimes uses a set of APIs (programming methods) called ‘REST API’ to send and receive requests to the WordPress database. If it fails to send and receive those requests, then some parts of your WordPress website may not be able to function. This…

Working From Home TV …

Tips to enhance your own website…

How to Track Website Visitors to Your WordPress Site – Website Tips

How to Track Website Visitors to Your WordPress Site – Website Tips

Are you looking for an easy way to track your website visitors in WordPress? Tracking the number of website visitors on your site can help you get insights to grow your business. You can better understand your audience, look at which posts they like, where they come from, and how they use your website. In this article, we’ll show you how to easily track website visitors on your WordPress site (step by step). Why You Need to Track Your Website Visitors Tracking website traffic is one of the most important indicators of your website’s performance. More visitors means more opportunities for converting them into subscribers and customers. It also unlocks promising insights that you may have missed. For example, you can find out which country or city your visitors are from. This can help you deliver personalized content or figure out which languages you should translate your website in. You…

How to Fix WordPress Updating Failed / Publishing Failed Error – Website Tips

How to Fix WordPress Updating Failed / Publishing Failed Error – Website Tips

Are you trying to fix the WordPress updating failed or publishing failed error on your website? Sometimes when editing a post or page, you may see the updating failed or publishing failed error. This error does not give any clues, which makes it particularly difficult for beginners. In this article, we’ll show you how to easily fix the WordPress updating failed error. We’ll also explain what causes this issue, and how to avoid this in the future. What Causes Updating Failed or Publishing Failed Error in WordPress? Failure to communicate with the WordPress REST API causes the ‘Updating Failed’ or ‘Publishing Failed’ error in WordPress. Basically, WordPress sometimes uses a set of APIs (programming methods) called ‘REST API’ to send and receive requests to the WordPress database. If it fails to send and receive those requests, then some parts of your WordPress website may not be able to function. This…

12 WordPress Search Plugins to Improve Your Site Search – Website Tips

12 WordPress Search Plugins to Improve Your Site Search – Website Tips

Are you looking for the best WordPress search plugin to improve your site search? We all know that the default WordPress search feature is quite limited. However, there are several WordPress search plugins that can help you improve the default search experience. In this article, we will highlight the best WordPress search plugins to improve your site search. Why Use a WordPress Search Plugin? WordPress comes with a built-in search feature, which is quite limited and not very good in finding the relevant content. If you are making a new WordPress website or blog, then you may not need a better search feature right away. However, as you add more content, you would want to help users easily find articles or products. A lot of folks rely mainly on SEO best practices, hoping that users will find things through search engines. Adding a site search helps users who are already…

0 Comments

Submit a Comment

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

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