Get terms attached to the post
$post_terms = get_the_terms(get_the_ID(), \'portfolio_category\');
if( is_array($post_terms) ) {
$post_terms = array_reduce($post_terms, function($carry, $item){
$carry[] = $item->slug;
return $carry;
}, []);
echo implode(\', \', $post_terms);
}
<小时>
Get all terms 要从给定的分类中检索所有术语,请使用函数get_terms
. Here 您将找到有关已接受参数的信息。
自WP 4.5起:
$portfolio_terms = get_terms([
\'taxonomy\' => \'portfolio_category\',
\'hide_empty\' => false,
\'fields\' => \'id=>slug\',
\'orderby\' => \'slug\',
]);
if( is_array($portfolio_terms) )
echo implode(\', \', $portfolio_terms);
WP 4.5之前:
$portfolio_terms = get_terms(\'portfolio_category\', [
\'hide_empty\' => false,
\'fields\' => \'id=>slug\',
\'orderby\' => \'slug\',
]);
if( is_array($portfolio_terms) )
echo implode(\', \', $portfolio_terms);