获取循环中当前自定义帖子的自定义类别ID

时间:2014-11-28 作者:akmur

我在检索正在查看的自定义帖子的当前类别的名称(或ID)(在循环中)时遇到了极大的困难。

当前类别名称为“school”,是名为“category\\u news”的自定义类别的子类别

我正在尝试以下操作,但返回为空。

$terms = get_the_terms( $post->ID , \'category_news\' );
if ( $terms != null ){
    foreach( $terms as $term ) {
        print $term->slug ;
        unset($term);
    }
}

1 个回复
最合适的回答,由SO网友:Rakhi 整理而成

get_the_terms( $id, $taxonomy ); 
第二个参数应该是分类名称,而不是类别名称

结束

相关推荐