Im trying to display the current post category name for a custom post types' taxonomy, but exclude one of the categories. I see different solutions in StackOverflow, but I can't seem to get any of them to work for me. Below is the code I am using, which works great, but I don't know how to exclude one ID using it.
<?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 ;
}
?>
CodePudding user response:
Try this
<?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;
if ($term->term_id != 222)
{
echo $term->name;
}
}
?>
Change 222 in this line to your taxonomy id for exclude
$term->term_id != 222