我有一个小问题,我在类别页面上显示类别的自定义字段。现在一切正常。但如果该类别中没有帖子,则不会显示。
我不知道在我的代码中在哪里使用'hide_empty‘=> 0。
这是我用来显示类别字段的代码。
$terms = get_the_terms( get_the_ID(), 'category');
if( !empty($terms) ) {
$term = array_pop($terms);
$expert_photo = get_field('expert_photo',$term);
$expert_name = get_field('expert_name',$term);
$expert_title = get_field('expert_title',$term);
$expert_description = get_field('expert_description',$term);
$expert_introduction = get_field('expert_introduction',$term);发布于 2016-03-31 15:01:30
get_the_terms的功能是检索附加到帖子的分类术语。
如果你想获得所有类别,你可以使用下面的代码
$categories = get_categories(array('orderby'=>'name','hide_empty'=>false));
echo "<pre>";
print_r($categories);https://stackoverflow.com/questions/36322383
复制相似问题