Skip to content

Instantly share code, notes, and snippets.

@thetwopct
Last active December 22, 2018 05:54
Show Gist options
  • Save thetwopct/3ac7cb83ef9ae59e00a2675fce9c5773 to your computer and use it in GitHub Desktop.
Save thetwopct/3ac7cb83ef9ae59e00a2675fce9c5773 to your computer and use it in GitHub Desktop.
Show taxonomies of a CPT post as links without comma at end
// array of CPTs (add more or less as required)
$myarray = array('custompost1','custompost2','custompost3');
$terms = get_the_terms( $post->ID , $myarray );
// init counter
$i = 1;
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, $myarray );
if( is_wp_error( $term_link ) )
continue;
echo '<a href="' . $term_link . '">' . $term->name . '</a>';
// Add comma (except after the last theme)
echo ($i < count($terms))? ", " : "";
// Increment counter
$i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment