使用wp_get_post_terms()
而是:
<?php
$names = wp_get_post_terms(
$post->ID,
\'winetype\',
array(
\'orderby\' => \'name\',
\'order\' => \'DESC\',
\'fields\' => \'names\'
);
echo implode(\', \', $names); // to avoid trailing separator
Updated 凭借to@Pieter Goosen评论。
$terms = get_the_terms( $post->ID , \'winetype\' );
if($terms) { // check the variable is not empty
// compare terms
function cmp($a, $b)
{
return strcmp($b->name, $a->name); // in reverse order to get DESC
}
// sort terms using comparison function
usort($terms, \'cmp\');
// get names from objects
function my_function($z)
{
return $z->name;
}
// map names array using my_function()
$term_names = array_map(\'my_function\', $terms);
// define separator
$separator = \', \';
// get string by imploding the array using the separator
$term_names = implode($separator, $term_names);
echo $term_names; // OR return
}