I am using tag.php to display content when a user visits a tag page. Everything I need is working great, however it is only showing the most recent 6 posts that have the tag. I need it to list all posts with the tag.

When I change the "Blog pages show at most" under Reading to a large number, it breaks part of my site so I would like to do it in the tag.php code.

I know you can list all posts by using the 'posts_per_page' => -1 parameter, but am having trouble implementing that into my code.

This is in my tag.php file


        if ( have_posts() ) : ?>

            <?php $term_id = get_queried_object_id(); ?>
            <div class="pantry-thumbnail"><?php the_term_thumbnail( $term_id, $size = 'post-thumbnail', $attr = '' ) ?></div>

                // Show an optional term description.
                $term_description = term_description();
                if ( ! empty( $term_description ) ) :
                    printf( '<div class="taxonomy-description">%s</div>', $term_description );


                // Start the Loop.
                while ( have_posts() ) : the_post();


                  <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>


                else :
                    // If no content, include the "No posts found" template.
                    get_template_part( 'content', 'none' );



Thank you for any help!

  • 1
    You might want to try a custom WP_Query since the default loop is only going to pull in a max of "blog pages show at most".
    – WebElaine
    Feb 13, 2017 at 19:41
  • I have tried creating a custom query, and all I was able to accomplish was listing all posts, not posts related to the tag. Would you mind helping me with doing that specifically in this code?
    – Hope
    Feb 13, 2017 at 19:43

1 Answer 1


I was able to fix this issue by adding this to the functions.php file

function wpa69774_limit_tags( $query ) {
 if ( $query->is_tag() && $query->is_main_query() ) {
    $query->set( 'posts_per_page', -1 );
add_action( 'pre_get_posts', 'wpa69774_limit_tags' );

after finally stumbling upon this question: Can't Get 'tag' Page To Display only Tagged Posts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.