6

For example, I have a link on my site like /tag/green and select content from all posts tagged green are shown using a file loop-tag.php which is about as simple as

<?php
if ( have_posts() ) :  while ( have_posts() ) : the_post();  ?>
<!-- Here I grab the image from the post with that tag -->  
<?php endwhile;  ?>

This works however it is being limited to 10 posts. Why is this being limited to 10 like this?

1 Answer 1

17

Because it must be set in back end of your wordpress site. You can check and change it from Blog pages show at most field from settings => Reading pages menu. As shown in below screenshot.

Blog pages show at most

It will change the setting for all pages , but if you want to make this change only for tag page then in your case you can change the code in loop-tag.php file as following :

global $wp;
$s_array = array( 'posts_per_page' => -1 );  // Change to how many posts you want to display 
$new_query = array_merge( $s_array, (array) $wp->query_vars );

// The Query
$the_query = new WP_Query( $new_query );

// The Loop
if ( $the_query->have_posts() ) {

    while ( $the_query->have_posts() ) {
        $the_query->the_post();
         ?>
        <!-- Here I grab the image from the post with that tag --> 
        <?php
    }

    /* Restore original Post Data */
    wp_reset_postdata();
}

You can also use pre_get_posts action hook to change post limit.

2
  • Thank you for the excellent explanation! I do want to make this independent of admin settings so that custom query is perfect.
    – zac
    Mar 4, 2013 at 8:31
  • 4
    @vinod_dalvi Can you update your post to use new WP_Query() instead of query_posts() which is not recommended. Also @Zac, if you want to adjust the number of posts only on a particular template, you should use the pre_get_posts filter, so you do not run the query twice. Mar 14, 2013 at 12:41

Your Answer

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

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