首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress获取类别字段,即使没有帖子

Wordpress获取类别字段,即使没有帖子
EN

Stack Overflow用户
提问于 2016-03-31 08:55:42
回答 1查看 42关注 0票数 0

我有一个小问题,我在类别页面上显示类别的自定义字段。现在一切正常。但如果该类别中没有帖子,则不会显示。

我不知道在我的代码中在哪里使用'hide_empty‘=> 0。

这是我用来显示类别字段的代码。

代码语言:javascript
复制
$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);
EN

回答 1

Stack Overflow用户

发布于 2016-03-31 15:01:30

get_the_terms的功能是检索附加到帖子的分类术语。

如果你想获得所有类别,你可以使用下面的代码

代码语言:javascript
复制
$categories =  get_categories(array('orderby'=>'name','hide_empty'=>false));
echo "<pre>";
print_r($categories);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36322383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档