July 12, 2016
Great way to hide categories from the front end if they are reserved for a different purpose:
function get_modified_term_list( $id = 0, $taxonomy, $before = '', $sep = '', $after = '', $exclude = array() ) {
$terms = get_the_terms( $id, $taxonomy );
if ( is_wp_error( $terms ) )
return $terms;
if ( empty( $terms ) )
return false;
foreach ( $terms as $term ) {
if(!in_array($term->term_id,$exclude)) {
$link = get_term_link( $term, $taxonomy );
if ( is_wp_error( $link ) )
return $link;
$term_links[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>'; // adjust here to alter appearance of the term on the front end
}
}
if( !isset( $term_links ) )
return false;
return $before . join( $sep, $term_links ) . $after;
}
Show the terms in the template:
<?php echo get_modified_term_list( get_the_ID(), 'project_category', '', ' ', '', array(20) ); ?>
Sourced here.
Brilliant. Thanks! That works perfectly.
Glad to hear it worked out for you!
Thank you so much for this, Katherine! It worked perfectly for me!