Skip to content

Instantly share code, notes, and snippets.

@carlitoescobar
Last active September 30, 2015 14:32
Show Gist options
  • Save carlitoescobar/b20fbc10bb7b273059d1 to your computer and use it in GitHub Desktop.
Save carlitoescobar/b20fbc10bb7b273059d1 to your computer and use it in GitHub Desktop.
Only return taxonomies that exist in current loop. Using it on another taxonomy terms archive page.
<?php
while (have_posts()) : the_post();
$taxonomy = 'your_taxonomy'; // change this to your taxonomy
//$terms = wp_get_post_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
$terms = wp_get_post_terms( $post->ID, $taxonomy, array( "fields" => "slugs" ) );
if( $terms ) $all_terms = array_merge($all_terms, $terms);
endwhile;
if ($all_terms) :
$all_terms = array_unique($all_terms);
//$terms = trim( implode( ' ', (array) $all_terms ), ' ,' );
echo '<ul>';
//wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms );
//echo $terms;
foreach ( $all_terms as $termname ) {
echo '<li>' . $termname . '</li>';
}
echo '</ul>';
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment