Created
May 6, 2014 21:20
-
-
Save barbwiredmedia/20674a913a8beee0d682 to your computer and use it in GitHub Desktop.
Will output all the terms for custom taxonomies. http://codex.wordpress.org/Function_Reference/get_the_terms#Get_terms_for_all_custom_taxonomies
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
// get taxonomies terms links | |
function custom_taxonomies_terms_links(){ | |
// get post by post id | |
$post = get_post( $post->ID ); | |
// get post type by post | |
$post_type = $post->post_type; | |
// get post type taxonomies | |
$taxonomies = get_object_taxonomies( $post_type, 'objects' ); | |
$out = array(); | |
foreach ( $taxonomies as $taxonomy_slug => $taxonomy ){ | |
// get the terms related to post | |
$terms = get_the_terms( $post->ID, $taxonomy_slug ); | |
if ( !empty( $terms ) ) { | |
$out[] = "<h2>" . $taxonomy->label . "</h2>\n<ul>"; | |
foreach ( $terms as $term ) { | |
$out[] = | |
' <li><a href="' | |
. get_term_link( $term->slug, $taxonomy_slug ) .'">' | |
. $term->name | |
. "</a></li>\n"; | |
} | |
$out[] = "</ul>\n"; | |
} | |
} | |
return implode('', $out ); | |
} | |
echo custom_taxonomies_terms_links(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment