Edit tags page for hierarchical taxonomy doesn’t show taxonomies at all depths

I created a taxonomy called “portfolio categories” for my portfolio custom post type. They’re hierarchical and supposed to be behave like categories. when i’m editing a single portfolio post… i have a metabox where i can assign the proper portfolio category. It shows all categories at all the depths.

unlimited hierarchy

but when i am on the Taxonomy page (edit-tags.php?taxonomy=portfolio-cats&post_type=portfolio) then it only shows top level categories and their immediate children… and no further. so grandchild-level categories are missing even though there are portfolio pieces assigned to them.

limited hierarchy

is this default behavior? b/c i can see unlimited depths on the regular Categories page. should a hierarchical taxonomy behave the same?

/*
 * Builds the a tag taxonomies
 */

function create_portfolio_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
  $labels = array(
    'name' => _x( 'Portfolio Categories', 'taxonomy general name' ),
    'singular_name' => _x( 'Portfolio Category', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Portfolio Categories' ),
    'all_items' => __( 'All Portfolio Categories' ),
    'parent_item' => __( 'Parent Portfolio Category' ),
    'parent_item_colon' => __( 'Parent Portfolio Category:' ),
    'edit_item' => __( 'Edit Portfolio Category' ), 
    'update_item' => __( 'Update Portfolio Category' ),
    'add_new_item' => __( 'Add New Portfolio Category' ),
    'new_item_name' => __( 'New Portfolio Category Name' ),
    'menu_name' => __( 'Portfolio Categories' ),
  );    

    register_taxonomy( 'portfolio-cats', array('portfolio'), 
        array( 
            'hierarchical' => true, 
            'labels' => $labels, 
            'rewrite' => array( 'slug' => 'portfolio','with_front' => true, 'hierarchical' => true  ),
        ) );

    //preset some categories
    my_add_term($postID,'portfolio-cats','Print');  
    my_add_term($postID,'portfolio-cats','Digital');

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



function my_add_term($id, $tax, $term) {

    $term_id = intval(term_exists($term));
    if (!$term_id) {
        $term_id = wp_insert_term($term, $tax);
        $term_id = $term_id['term_id'];
    }
    $result =  wp_set_object_terms($id, array($term_id), $tax, FALSE);

    return $result;
}

1 Answer
1

Pretty bizarre issue. I popped in that same code and successfully replicated the issue. I then removed the calls to my_add_term, reset my permalinks (not sure if this helped or not but worth mentioning that I did it), added an item, reloaded, and they all showed up in heirarchy as expected.

In the calls to my_add_term, you’re passing $postID but that isn’t defined, so I’m guessing that’s where the issue is coming from. Bottom line, you don’t need to define Print and Digital as your base categories with every single page load, so that code can reasonably be removed. Let me know if this fixes it for you!

Cheers~

Leave a Comment