Skip to content

Instantly share code, notes, and snippets.

@croosen
Last active August 29, 2015 14:06
Show Gist options
  • Save croosen/f8ffcf8dfc427492f827 to your computer and use it in GitHub Desktop.
Save croosen/f8ffcf8dfc427492f827 to your computer and use it in GitHub Desktop.
WordPress - Show categories that belong to the current custom post
<?php
$taxonomy = 'foo_cat'; // Your category
$terms = get_the_terms($post->ID, $taxonomy ); // Get data for post ID
if ( $terms && !is_wp_error( $terms ) ) :
?>
<?php foreach ( $terms as $term ) { ?>
<li><a href="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?></a></li>
<?php } ?>
<?php endif;?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment