I’m not sure what you want, but if you are trying to get a unique <li>
-list from the query you can try (untested):
<?php
// LOOP ARGUMENTS
$args = array( 'post_type' => 'xyz_members', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'tax_query' => array(array('taxonomy' => 'member_types','field' => 'slug','terms' => 'current-class','operator' => 'NOT IN')));
$loop = new WP_Query( $args );
$tags = array();
// COLLECT
while ( $loop->have_posts() ) : $loop->the_post();
$postTags = get_the_tags();
if ($postTags):
while($postTags as $tag):
$tags[$tag->slug] = $tag->slug;
endwhile;
endif;
endwhile;
// OUTPUT
$years = range( 2006, 2020 );
foreach( $years as $year ):
$year = (string) $year;
if( isset( $tags[$year] ) )
printf('<li id="_%s" class="filter on">%s</li>', $tags[$year], $tags[$year] );
endforeach;
?>
You could also consider array_unique()
to remove duplicate values from an array.