【发布时间】:2021-10-08 16:24:34
【问题描述】:
我试图显示自定义帖子类型分类的当前帖子类别名称,但排除其中一个类别。我在 StackOverflow 中看到了不同的解决方案,但我似乎无法让它们中的任何一个为我工作。下面是我正在使用的代码,效果很好,但我不知道如何使用它来排除一个 ID。
<?php $terms = get_the_terms( $post->ID , 'press_category' );
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'press_category' );
if( is_wp_error( $term_link ) )
continue;
echo $term->name ;
}
?>
【问题讨论】: