Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save frankyonnetti/709e34e00a02bb76e634a1e6139d2c55 to your computer and use it in GitHub Desktop.

Select an option

Save frankyonnetti/709e34e00a02bb76e634a1e6139d2c55 to your computer and use it in GitHub Desktop.
WordPress - Get terms from post #wordpress #taxonomy
<?php
// project_tag is the term parent
<?php if (has_term($post->ID, 'project_tag')): ?>
<div class="blog-focus-areas">
<h3>Related Focus Areas</h3>
<?php echo get_the_term_list($post->ID, 'project_tag', '<ul><li>', ',</li><li>', '</li></ul>'); ?>
</div>
<?php endif; ?>
-- or --
<?php $focus_areas = get_the_terms( $post->ID, 'project_tag' ); ?>
<?php foreach ( $focus_areas as $focus_area ): ?>
<?php echo get_the_term_list( $focus_area, 'project_tag', '', ', ' ); ?>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment