I am using the following code to create a list of linked terms belonging to a taxonomy.
<?php
$taxonomy = 'taxonomy_name';
$queried_term = get_query_var($taxonomy);
$terms = get_terms($taxonomy, 'slug='.$queried_term);
if ($terms) {
echo '<ul>';
foreach($terms as $term) {
echo '<li><a href="'.get_term_link($term->slug, $taxonomy).'">'.$term->name.'</a></li>';
}
echo '</ul>';
}
?>
Is there a way that I can modify this so that once a term is selected/clicked and the archive is shown, the term list will then only show terms that are also attached to posts in the current term archive - effectively like a filtering/drill-down system?