I have the following code and I'm trying to check to see if a specific tag exists, and if so, I need to echo it once. The problem is when the tag exists in multiple places, it echos multiple times.
// 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 );
while ( $loop->have_posts() ) : $loop->the_post();
// CUSTOM CONTENT
$postTags = get_the_tags();
if ($postTags) while($postTags as $tag) {
if ($tag->slug == '2006') { ?><li id="_2013" class="filter on">2006</li><?php }
if ($tag->slug == '2007') { ?><li id="_2013" class="filter on">2007</li><?php }
if ($tag->slug == '2008') { ?><li id="_2013" class="filter on">2008</li><?php }
if ($tag->slug == '2009') { ?><li id="_2013" class="filter on">2009</li><?php }
if ($tag->slug == '2010') { ?><li id="_2013" class="filter on">2010</li><?php }
if ($tag->slug == '2011') { ?><li id="_2013" class="filter on">2011</li><?php }
if ($tag->slug == '2012') { ?><li id="_2013" class="filter on">2012</li><?php }
if ($tag->slug == '2013') { ?><li id="_2013" class="filter on">2013</li><?php }
if ($tag->slug == '2014') { ?><li id="_2013" class="filter on">2014</li><?php }
if ($tag->slug == '2015') { ?><li id="_2013" class="filter on">2015</li><?php }
if ($tag->slug == '2016') { ?><li id="_2013" class="filter on">2016</li><?php }
if ($tag->slug == '2017') { ?><li id="_2013" class="filter on">2017</li><?php }
if ($tag->slug == '2018') { ?><li id="_2013" class="filter on">2018</li><?php }
if ($tag->slug == '2019') { ?><li id="_2013" class="filter on">2019</li><?php }
if ($tag->slug == '2020') { ?><li id="_2013" class="filter on">2020</li><?php }
}
/* END WHILE AND RESET QUERY */
endwhile; wp_reset_query();