如何列出自定义帖子类型中的所有类别? [英] How to list all category from custom post type?

查看:27
本文介绍了如何列出自定义帖子类型中的所有类别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为dining"的帖子类型,还有一个名为dining-category"的分类法.

I have a post type called 'dining' and has a taxonomy called 'dining-category'.

我想要做的是,我想在我的页脚区域显示帖子类型餐饮"中的所有类别.

What I want to do is, I want to display all the category from post type 'dining' in my footer area.

推荐答案

在 WordPress 4.6 中 get_terms 已弃用.所以有一个替代方法(get_categories)阅读这个

In WordPress 4.6 get_terms is deprecated. So there is an alternate of this (get_categories) Read this

这是示例代码:

<?php
   $args = array(
               'taxonomy' => 'dining-category',
               'orderby' => 'name',
               'order'   => 'ASC'
           );

   $cats = get_categories($args);

   foreach($cats as $cat) {
?>
      <a href="<?php echo get_category_link( $cat->term_id ) ?>">
           <?php echo $cat->name; ?>
      </a>
<?php
   }
?>

希望对您有所帮助.

这篇关于如何列出自定义帖子类型中的所有类别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆