自定义帖子类型中的Wordpress列表类别

问题描述:

我有一个查询,我只想列出分配给当前正在查看的帖子的那些类别。自定义帖子类型中的Wordpress列表类别

目前,它列出了我的自定义帖子类型的所有类别。 是否可以列出这些个人职位?帖子类型被称为“资源”,并且附加到该帖子类型的类别被称为“资源类别”。

<?php 
     $taxonomy = 'resource-category'; 
     $tax_terms = get_terms($taxonomy); 
     ?> 
    <?php 
     foreach ($tax_terms as $tax_term) { 
     echo '' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf(__("View all posts in %s"), $tax_term->name) . '" ' . '>' . $tax_term->name.'</a>&nbsp;&nbsp;&nbsp; '; 
     } 
?> 

您可以使用wp_get_post_terms

<?php 

$taxonomy = 'resource-category'; 
$tax_terms = wp_get_post_terms($post->ID, $taxonomy, array("fields" => "all")); 

foreach ($tax_terms as $tax_term) { 
    echo '' . '<a href="' . esc_attr(get_term_link($tax_term->term_id, $taxonomy)) . '" title="' . sprintf(__("View all posts in %s"), $tax_term->name) . '" ' . '>' . $tax_term->name.'</a>&nbsp;&nbsp;&nbsp; '; 
} 

?> 
+0

完美工作,谢谢! – lowercase