我有一个自定义的帖子类型,它有一个名为“country”的自定义分类 . 我想在仪表板 - >主题选项中的下拉列表中选择此分类法下的术语名称 . 所以我创建了以下函数:
function featured_country($show_count = false, $country_array = array()) {
$countries = get_terms( 'category', 'hide_empty=0&fields=all' );
foreach ($countries as $countr) {
$country_array[$countr->term_id] = $countr->name;
}
return $country_array;
}
然后我调用这个函数如下:
$this->admin_option('Front Page Option',
'Featured country', 'featured_country',
'select', '',
array('options'=>$this->featured_country(true, array(''=>'Select Category')),
'help'=>'Some helping text')
);
不幸的是,这个下拉列表什么都没显示 . 但是当我将get_terms()的参数作为“category”或“link_category”时,它可以工作 .
我无法理解我的问题在哪里 . 我怎么解决这个问题?请帮我 .
2 回答
试试这段代码
(我从这个forum thread拿走了它)
以下是自定义分类“为 courses " & custom post type for that is " help_lessions ”的示例