Skip to content

Instantly share code, notes, and snippets.

Created February 23, 2015 20:44
Show Gist options
  • Save anonymous/582f0c45e35ae8c38561 to your computer and use it in GitHub Desktop.
Save anonymous/582f0c45e35ae8c38561 to your computer and use it in GitHub Desktop.
How to get the term links for a specific post
<?php
$taxonomy = 'project_category';
$terms = wp_get_post_terms($post->ID, $taxonomy);
//print_rr($terms);
foreach ($terms as $term) {
$term_link = get_term_link( $term, $taxonomy );
if ( is_wp_error( $term_link ) )
echo $term_link->get_error_message();
if ( is_wp_error( $term_link ) ) {
continue;
} ?>
<li><a href="<?php echo esc_url( $term_link ); ?>"><?php echo $term->name; ?></a></li>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment