Friday, 7 June 2013

If tag exists and equals then

If tag exists and equals then

I have the following code and I'm trying to check to see if a specific tag exists and if so I need it to be echo'd once. The problem I'm having is when the tag exists multiple places it gets echo'd that many times.
                        <?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 );
                        while ( $loop->have_posts() ) : $loop->the_post();

                        // CUSTOM CONTENT
                        $postTags = get_the_tags();
                    ?>

                    <?php if ($postTags) while($postTags as $tag) { ?>
                        <?php if ($tag->slug == '2006') { ?><li id="_2013" class="filter on">2006</li><?php } ?>
                        <?php if ($tag->slug == '2007') { ?><li id="_2013" class="filter on">2007</li><?php } ?>
                        <?php if ($tag->slug == '2008') { ?><li id="_2013" class="filter on">2008</li><?php } ?>
                        <?php if ($tag->slug == '2009') { ?><li id="_2013" class="filter on">2009</li><?php } ?>
                        <?php if ($tag->slug == '2010') { ?><li id="_2013" class="filter on">2010</li><?php } ?>
                        <?php if ($tag->slug == '2011') { ?><li id="_2013" class="filter on">2011</li><?php } ?>
                        <?php if ($tag->slug == '2012') { ?><li id="_2013" class="filter on">2012</li><?php } ?>
                        <?php if ($tag->slug == '2013') { ?><li id="_2013" class="filter on">2013</li><?php } ?>
                        <?php if ($tag->slug == '2014') { ?><li id="_2013" class="filter on">2014</li><?php } ?>
                        <?php if ($tag->slug == '2015') { ?><li id="_2013" class="filter on">2015</li><?php } ?>
                        <?php if ($tag->slug == '2016') { ?><li id="_2013" class="filter on">2016</li><?php } ?>
                        <?php if ($tag->slug == '2017') { ?><li id="_2013" class="filter on">2017</li><?php } ?>
                        <?php if ($tag->slug == '2018') { ?><li id="_2013" class="filter on">2018</li><?php } ?>
                        <?php if ($tag->slug == '2019') { ?><li id="_2013" class="filter on">2019</li><?php } ?>
                        <?php if ($tag->slug == '2020') { ?><li id="_2013" class="filter on">2020</li><?php } ?>
                    <?php } ?>
                    <?php /* END WHILE AND RESET QUERY */ endwhile; wp_reset_query(); ?>

No comments:

Post a Comment