Skip to content

Instantly share code, notes, and snippets.

@javierarques
Created June 2, 2014 18:50
Show Gist options
  • Save javierarques/7ddf363051634b5fda50 to your computer and use it in GitHub Desktop.
Save javierarques/7ddf363051634b5fda50 to your computer and use it in GitHub Desktop.
[Wordpress] Get the term names of a post
/**
* Retrieve a post's terms as a list with specified format.
*
* @since 2.5.0
*
* @param int $id Post ID.
* @param string $taxonomy Taxonomy name.
* @param string $before Optional. Before list.
* @param string $sep Optional. Separate items using this.
* @param string $after Optional. After list.
* @return string
*/
function get_the_term_names( $id = 0, $taxonomy, $sep = '') {
$terms = get_the_terms( $id, $taxonomy );
if ( is_wp_error( $terms ) )
return $terms;
if ( empty( $terms ) )
return false;
foreach ( $terms as $term ) {
$term_names[] = $term->name;
}
return join( $sep, $term_names ) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment