对于自定义分类法,我可以使用什么而不是get_the_category()



基本上,我已经使用自定义分类法(custom_tax)创建了一个自定义帖子类型。现在,我创建了一个自定义查询,我想在其中获取自定义类别,其中保存自定义帖子并将其名称输出为字符串。我在使用WordPress标准分类法时正在这样做:

//Start the query
   query_posts(array(
  'showposts' => $posts,
  'orderby' => 'asc',
  'category_name' => $category
));
$temp_title = get_the_title();
$temp_link = get_permalink();
$temp_excerpt = get_the_excerpt();
$temp_time = get_the_date('Y-m-d');
$temp_categories = get_the_category(', ');
$temp_author = get_the_author();
$temp_content = get_the_content();
$i++;
$output2 .= "<li class='item' data-id='id-" . $i . "' data-type='" . $temp_categories . "'><a href='" . $temp_link . "' rel='prettyPhoto[portfolio]'><img class='' src='" . $path . "/library/timthumb.php?src=" . $image[0] . "&h=130&w=210&zc=1&q=100' alt='" . $temp_title . "' /></a></li>";

它就像魅力一样。现在,我需要使用自定义帖子和自定义分类法,并尝试了许多变体:

//Start the query
query_posts(array(
  'post_type' => array('post', 'portfolio'),
  'showposts' => $posts,
  'orderby' => 'asc',
  'category_name' => $category
));
$temp_title = get_the_title();
$temp_link = get_permalink();
$temp_excerpt = get_the_excerpt();
$temp_time = get_the_date('Y-m-d');
$temp_categories = get_the_terms( get_the_ID(), 'custom_cat', ', ' );
$temp_author = get_the_author();
$temp_content = get_the_content();
$i++;
$output2 .= "<li class='item' data-id='id-" . $i . "' data-type='" . $temp_categories . "'><a href='" . $temp_link . "' rel='prettyPhoto[portfolio]'><img class='' src='" . $path . "/library/timthumb.php?src=" . $image[0] . "&h=130&w=210&zc=1&q=100' alt='" . $temp_title . "' /></a></li>";

并且它不起作用。我已经尝试过get_the_terms(),the_terms()和get_terms(),但是没有一个像get_the_category()工作了 - 它正在输出带有类别名称的字符串。我想念什么?

非常感谢

WordPress将分类法描述为"术语"。在此处找到的" get_terms()"文档中可能会有一些帮助。如果您想按术语进行排序,那么WordPress论坛上有一篇很棒的帖子可以做到这一点!

最新更新