What is Taxonomy in WordPress?

Last Updated:June 30, 2021

In real world, taxonomy is the classification of something

Understand Taxonomy in WordPress

Taxonomy in WordPress Context

In WordPress, taxonomy is a way of grouping posts (or custom post) based on a relationship. In default WordPress, you have the taxonomy category and tags which are groups of the posts based on relationship.

You can create taxonomy called recipe, book etc

Default Taxonomy in WordPress

There are two types of taxonomy in WordPress default installation

They are:

1 Category

2 Tags

How to create a taxonomy

You can use two methods to create taxonomy in WordPress.

  1. Use WordPress Plugin
  2. Use manual method [add code to the function.php ]

You have a function called register_taxonomies() in WP codex to create new taxonomies

register_taxonomy( string $taxonomy, array|string $object_type, array|string $args = array() )

You have got several parameters for this function, the first one is the name of the taxonomy.

Add the following piece of code to your function.php file in your theme and you can see the new taxonomy appear under the post menu of the admin section.

Create taxonomy and associate with existing post type

add_action( 'init', 'create_taxonomy_topics', 0 );

function create_taxonomy_topics() {

// Labels 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 name topic just like ta and category

        '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' ),

You can see the taxonomy Topic under the Posts section

Create Taxnomy