Created
June 2, 2014 18:50
-
-
Save javierarques/7ddf363051634b5fda50 to your computer and use it in GitHub Desktop.
[Wordpress] Get the term names of a post
This file contains 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
/** | |
* 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