显示WP循环中某个帖子的所有分类

时间:2012-11-27 10:53:48

标签: wordpress taxonomy custom-post-type

这可能是一个简单的问题,但我无法抓住它。

我在wordpress中有自定义帖子类型的WP_query列表,我需要为列表中的每个项目显示适当的分类(类别)。

我尝试使用谷歌搜索和搜索stackoverflow但是做得很短。

此外,这是我用于显示特定帖子类型存在的所有分类标准的内容:

function get_taxonomy_classes($theID) {

        $post_type  = get_post_type($theID);
        $taxonomies = get_object_taxonomies($post_type, 'objects');

        $terms = get_terms($taxonomies, array(
            'orderby' => 'name',
            'order' => 'ASC',
            'hide_empty' => TRUE
        ));
        foreach($terms as $term) {
            echo $term->slug . " ";
        }

    }

仍未找到使用上述分类法的方法:(

请帮助,谢谢!

1 个答案:

答案 0 :(得分:1)

不管怎么说,伙计们。我自己找到了答案。

这很简单,你只需要wp_get_object_terms()函数

   $termss = wp_get_object_terms(get_the_ID(), 'portfolio_category');
   foreach ($termss as $term) {
      echo $term->slug;
   }