Skip to content

Instantly share code, notes, and snippets.

@FutureMedia
Created June 5, 2014 09:04
Show Gist options
  • Save FutureMedia/8c7266c08979fb6d43f2 to your computer and use it in GitHub Desktop.
Save FutureMedia/8c7266c08979fb6d43f2 to your computer and use it in GitHub Desktop.
Return a list of the custom taxonomies with links. (WP)
<?php
// Return a list of the custom taxonomies with links
function get_custom_taxonomies_list() {
global $post, $post_id;
// 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);
$out = "<ul>";
foreach ($taxonomies as $taxonomy) {
$out .= "<li>".$taxonomy.": ";
// get the terms related to post
$terms = get_the_terms( $post->ID, $taxonomy );
if ( !empty( $terms ) ) {
foreach ( $terms as $term )
$out .= '<a href="' .get_term_link($term->slug, $taxonomy) .'">'.$term->name.'</a> ';
}
$out .= "</li>";
}
$out .= "</ul>";
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment