Custom Taxonomy – Tags Metabox is showing instead of Categories

So I have a weird thing going on. Usually by default when you create taxonomies a categories metabox is made automatically (right?). For some reason that’s not showing up but Tags metabox is showing up instead and I have no idea why. I disabled all my plugins but it didn’t seem to help. What could cause this.

MY Custom Post Type

Read More
function CPT_init(){
    // Products CPT 
    register_post_type('product', array(
        'labels'            =>  array(
            'name'          =>      __('Products'),
            'singular_name' =>      __('Product'),
            'all_items'     =>      __('View Products'),
            'add_new'       =>      __('New Product'),
            'add_new_item'  =>      __('New Product'),
            'edit_item'     =>      __('Edit Product'),
            'view_item'     =>      __('View Product'),
            'search_items'  =>      __('Search Products'),
            'no_found'      =>      __('No Products Found'),
            'not_found_in_trash' => __('No Products in Trash')
                                ),
        'public'            =>  true,
        'publicly_queryable'=>  true,
        'show_ui'           =>  true, 
        'query_var'         =>  true,
        'show_in_nav_menus' =>  false,
        'capability_type'   =>  'post',
        'hierarchical'      =>  false,
        'menu_position'     =>  21,
        'supports'          =>  array('title','editor', 'thumbnail'),
        'has_archive'       =>  true
    ));
}
add_action('init', 'CPT_init');

My Taxonomy

function product_category_taxonomy() {
$labels = array(
        'name'              => __( 'Product Categories' ),
        'singular_name'     => __( 'Product Category' ),
        'search_items'      => __( 'Search Product Categories' ),
        'all_items'         => __( 'All Product Categories' ),
        'parent_item'       => __( 'Parent Product Category' ),
        'parent_item_colon' => __( 'Parent Product Category:' ),
        'edit_item'         => __( 'Edit Product Category' ), 
        'update_item'       => __( 'Update Product Category' ),
        'add_new_item'      => __( 'Add New Product Category' ),
        'new_item_name'     => __( 'New Product Category' ),
        'menu_name'         => __( 'Product Categories' ),
    ); 
    $args = array(
        'labels'            => $labels,
        'public'            =>  true,
        'show_in_nav_menus' =>  false,
        'has_archive'       =>  true,
        'rewrite'           =>  array('slug' => '/products', 'with_front' => true),
    );
    register_taxonomy( 'protax', 'product', $args );
}
add_action( 'init', 'product_category_taxonomy');

Pretty standard stuff. What’s causing tags to show up in the place of my categories metabox?

The tags metaboxes are named the same as my Taxonomy ‘name’ field. So it probably has something to do with my taxonomy. I tried to remove public and tried to turn show_tagcloud to false. Didn’t really do anything.

Related posts

1 comment

  1. You need to set hierarchical argument of your taxonomy to true (by default it’s false):

    function product_category_taxonomy() {
    $labels = array(
            'name'              => __( 'Product Categories' ),
            'singular_name'     => __( 'Product Category' ),
            'search_items'      => __( 'Search Product Categories' ),
            'all_items'         => __( 'All Product Categories' ),
            'parent_item'       => __( 'Parent Product Category' ),
            'parent_item_colon' => __( 'Parent Product Category:' ),
            'edit_item'         => __( 'Edit Product Category' ), 
            'update_item'       => __( 'Update Product Category' ),
            'add_new_item'      => __( 'Add New Product Category' ),
            'new_item_name'     => __( 'New Product Category' ),
            'menu_name'         => __( 'Product Categories' ),
        ); 
        $args = array(
            'labels'            => $labels,
            'public'            =>  true,
            'show_in_nav_menus' =>  false,
            'has_archive'       =>  true,
            'hierarchical'      =>  true,
            'rewrite'           =>  array('slug' => '/products', 'with_front' => true),
        );
        register_taxonomy( 'protax', 'product', $args );
    }
    add_action( 'init', 'product_category_taxonomy');
    

    Take a look at codex documentation.

Comments are closed.