Skip to content

Instantly share code, notes, and snippets.

@barbwiredmedia
Created May 6, 2014 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barbwiredmedia/20674a913a8beee0d682 to your computer and use it in GitHub Desktop.
Save barbwiredmedia/20674a913a8beee0d682 to your computer and use it in GitHub Desktop.
// 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