Query all posts with specific tag

It’s a lot easier to create a new WP_Query than it is to try clearing or overwriting the original.

If $post_tag is a tag slug, you could simply use:

<?php
$the_query = new WP_Query( 'tag='.$post_tag );

if ( $the_query->have_posts() ) {
    echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
} else {
    // no posts found
}
/* Restore original Post Data */
wp_reset_postdata();

Leave a Comment