Support » Theme: Sampression Lite » Filter Posts by Tag

  • I’m trying to filter the posts by tag instead of category. This is what I have so far…

    in header.php I changed this code…

    <?php
            $categories = get_categories();
            foreach($categories as $category):
            ?>
            <li><a href="javascript:void(0);" data-filter=".<?php echo $category->slug; ?>" id="<?php echo $category->slug; ?>" class="filter-data"><span></span><?php echo $category->name; ?></a></li>
            <?php
            endforeach;
            ?>

    to this code, basically replacing anything that say category with tag…

    <?php
            $tags = get_tags('include=202,82,16');
            foreach($tags as $tag):
            ?>
            <li><a href="javascript:void(0);" data-filter=".<?php echo $tag->slug; ?>" id="<?php echo $tag->slug; ?>" class="filter-data"><span></span><?php echo $tag->name; ?></a></li>
            <?php
            endforeach;
            ?>

    So instead of getting categories listed in the filter menu it now shows tags with IDs 202,82, and 16.

    All of that works great except when I click one of these filter tags it shows zero posts, even though I have plenty of posts with those tags.

    I feel like there is something in the script that i need to change to tell it to filter posts by tag instead of category.

    Anyone have any ideas?

  • The topic ‘Filter Posts by Tag’ is closed to new replies.