2

I'm working on building some custom taxonomies for a custom post type I created.

The custom post type is Products. For the custom post type Products I've created a taxonomy of Category. Now Under Category, I'd like to have a taxonomy of Sub_Category. I've created all the taxonomies and set them to hierarchical, but the Sub_Category tax seems to be relative to the Product Custom Post Type, NOT the Category custom taxonomy. Is there a way to do this? I saw a screenshot where someone was filling out a taxonomy form for a taxonomy they created and it had an option for PARENT but I could never get that to show up. How can I choose a PARENT Category taxonomy on my SubCategory taxonomy?

Here is my Category and SubCategory taxonomy code:

function create_productcategory_taxonomy() {
    $labels = array(
        'name' => _x( 'Categories', 'taxonomy general name' ),
        'singular_name' =>_x( 'Category', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Categories' ),
        'popular_items' => __( 'Popular Categories' ),
        'all_items' => __( 'All Categories' ),
        'parent_item' => null,
        'parent_item_colon' => null,
        'edit_item' => __( 'Edit Product Category' ),
        'update_item' => __( 'Update Product Category' ),
        'add_new_item' => __( 'Add New Product Category' ),
        'new_item_name' => __( 'New Product Category' ),
        'separate_items_with_commas' => __( 'Separate categories with commas' ),
        'add_or_remove_items' => __( 'Add or remove product categories' ),
        'choose_from_most_used' => __( 'Choose from the most used categories' )
        );

    register_taxonomy('tf_productcategory', 'tf_products', array (
        'label' => __('Product Category'),
        'labels' => $labels,
        'hierarchial' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'product-category'),
        )); 
}

function create_product_subcategory_taxonomy() {
    $labels = array(
        'name' => _x( 'SubCategories', 'taxonomy general name' ),
        'singular_name' =>_x( 'SubCategory', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search SubCategories' ),
        'popular_items' => __( 'Popular SubCategories' ),
        'all_items' => __( 'All SubCategories' ),
        'parent_item' => __( 'Main Category' ),
        'parent_item_colon' => ( 'Main Category:' ),
        'edit_item' => __( 'Edit Product SubCategory' ),
        'update_item' => __( 'Update Product SubCategory' ),
        'add_new_item' => __( 'Add New Product SubCategory' ),
        'new_item_name' => __( 'New Product SubCategory' ),
        'menu_name' => __( 'SubCategories' )
        );

    register_taxonomy('tf_productsubcategory', 'tf_products', array (
        'label' => __('Product SubCategory'),
        'labels' => $labels,
        'hierarchial' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'product-subcategory'),
        )); 
}

add_action( 'init', 'create_productcategory_taxonomy', 0 );
add_action( 'init', 'create_product_subcategory_taxonomy', 0 );

1 Answer 1

2

Hierarchical refers to the terms relation to each other not the taxonomies relation to another taxonomy. Non hierarchical taxonomies are like tags they don't have parents or children. Hierarchical taxonomies means that the terms can have parents and children.

taxonomy = category

category terms:

  • blue products (parent term)

    • light blue products (child term)
    • dark blue products (child term)
  • red products (parent term)

    • dark red products (child term)
    • light red products (child term)

Also in your code above change:

'hierarchial' => true,

To:

'hierarchical' => true,
4
  • Wow thank you! That one typo was killing my spirit. It wouldn't let me pick existing Taxonomies for custom posts types, I was just trying to figure out why. Thanks for the explanation too, makes perfect sense! Commented Apr 27, 2011 at 21:32
  • Oh I see now, there is no need to make a SubCategory taxonomy then right? I can just make One category the parent of another? Commented Apr 27, 2011 at 21:33
  • @drpcken I'm horrible with spelling and I had to check Google to make sure which was the correct spelling. lol
    – Chris_O
    Commented Apr 27, 2011 at 21:34
  • 1
    @drpcken yes just make a tax of product-type. I did something similar for a liquor company and tax is product-type and terms are liquor, beer, wine and sub terms are under each parent like liquor -> gin, vodka, rum etc...
    – Chris_O
    Commented Apr 27, 2011 at 21:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.