Last active
December 22, 2018 05:54
-
-
Save thetwopct/3ac7cb83ef9ae59e00a2675fce9c5773 to your computer and use it in GitHub Desktop.
Show taxonomies of a CPT post as links without comma at end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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