Skip to content

Instantly share code, notes, and snippets.

@yratof
Created March 12, 2014 22:39
Show Gist options
  • Save yratof/9518025 to your computer and use it in GitHub Desktop.
Save yratof/9518025 to your computer and use it in GitHub Desktop.
<?php
$taxonomy = 'category';
// get the term IDs assigned to post.
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
// separator between links
$separator = ', ';
if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {
$term_ids = implode( ',' , $post_terms );
$terms = wp_list_categories( 'title_li=&style=none&echo=0&taxonomy=' . $taxonomy . '&include=' . $term_ids );
$terms = rtrim( trim( str_replace( '<br />', $separator, $terms ) ), $separator );
// display post categories
echo $terms;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment