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.
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.
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;
}