我不知道你想要什么,但如果你想得到一个独特的<li>
-可以尝试的查询列表(未测试):
<?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;
?>
你也可以考虑
array_unique()
从数组中删除重复值。