我正在尝试使用以下代码显示自定义分类术语及其描述的列表。
我遇到的问题是与自定义帖子类型无关的分类术语(即为空的分类术语)不会显示在列表中。知道如何让它们显示吗?
$institutions = get_terms('institutions');
foreach($institutions as $institution) {
// variables
$link = get_term_link(intval($institution->term_id),'institutions');
$description = term_description(intval($institution->term_id),'institutions');
// output
echo '<article>';
echo '<h3><a href="' . $link . '">' . $institution->name . '</a></h3>' . strip_tags(substr($description,0,350)) . '...';
echo '</article>';
};
这是我用来注册分类的代码:
add_action( 'init', 'inst_taxonomies', 0 );
function inst_taxonomies() {
$htinstutitions_labels = array(
'name' => _x( 'Institutions', 'taxonomy general name' ),
'singular_name' => _x( 'Institution', 'taxonomy singular name' ),
'search_items' => __( 'Search in institutions' ),
'all_items' => __( 'All institutions' ),
'most_used_items' => null,
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit institution' ),
'update_item' => __( 'Update institution' ),
'add_new_item' => __( 'Add new institution' ),
'new_item_name' => __( 'New institution' ),
'menu_name' => __( 'Institutions' ),
);
register_taxonomy('institutions',array('jobs'),array(
'hierarchical' => true,
'labels' => $htinstutitions_labels,
'show_admin_column' => true,
'has_archive' => true,
'show_ui' => true,
'query_var' => true,
'hide_empty' => 0,
'rewrite' => array('slug' => 'institutions' )
));
}