我为我的公文包自定义帖子类型创建了一个名为“公文包类别”的分类法。它们是分级的,应该表现得像类别。当我编辑一篇文章时。。。我有一个元数据库,可以在其中分配适当的投资组合类别。它显示所有深度的所有类别。
但是当我在分类页面上(编辑tags.php?Taxonomy=portfolio cat&post\\u type=portfolio)时,它只显示顶级类别及其直接子类别。。。再也没有了。因此,孙子级别的类别缺失,即使有分配给它们的投资组合条目。
这是默认行为吗?b/c我可以在常规类别页面上看到无限深度。层次分类法的行为应该相同吗?
/*
* 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;
}