2012-11-27 21 views
0

這可能是一個簡單的問題,但我無法繞過它。顯示WP循環中某個帖子的所有分類標準

我有一個WP_query列表中的自定義帖子類型在wordpress中,我需要爲列表中的每個項目顯示適當的分類法(類別)。

我試過Google搜索並通過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

沒關係,夥計們,我找到了答案我自己。

這很簡單,你只需要wp_get_object_terms()函數

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