我有一个自定义的帖子类型'事件'和分类 - '事件类型' . 如何在数组中获取属于自定义分类“事件类型”的所有术语 . 我使用wp_list_categories($ args)但它给出了Ali标签中每种类型的输出 .
请帮帮我
注册分类法的代码
<?php
function event_init() {
// create a new taxonomy
register_taxonomy(
'Event types',
'events',
array(
'labels' => array(
'name'=>'Event types',
'add_new_item'=>'Add New Event types ',
'new_item_name'=>"New Event types"
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'event-type' ),
)
);
}
add_action( 'init', 'event_init' );
?>
2 回答
这将为您提供一系列术语对象 . Note 您的分类名称必须仅为小写字母和下划线 .
参考:http://codex.wordpress.org/Function_Reference/get_terms
$ terms = get_terms('事件类型');
这对你有用 . 为了获得更好的体验,请不要在分类法的名称或任何其他变量名称中使用大写字母和空格 .
参考:https://developer.wordpress.org/reference/functions/get_terms/