获取当前帖子ID的the_terms名称

时间:2013-02-10 13:03:48

标签: php wordpress custom-taxonomy

当我想获得包含分类法所有名称的数组时,这对我有用:

get_terms( 'portfolio-skills', array( 'fields' => 'names' ) );

如果我想获取与当前帖子相关联的术语名称,该怎么办?我试过这个,但它不起作用:

get_terms( 'portfolio-skills', array( 'fields' => 'names' ), 'include' => array( $post->ID ) );

2 个答案:

答案 0 :(得分:4)

谢谢@Pekka웃,我改变了它,它正在发挥作用:

wp_get_object_terms( $post->ID, 'portfolio-skills', array( 'fields' => 'names' ) );

答案 1 :(得分:0)

$term_list = get_the_terms($post->ID, 'your_taxonomy');
$types ='';
foreach($term_list as $term_single) {
     $types .= ucfirst($term_single->slug).', ';
}
$typesz = rtrim($types, ', ');
echo $typesz;