Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 13 down vote accepted

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 );
query_posts($new_query);
<?php
if ( have_posts() ) :  while ( have_posts() ) : the_post();  ?>
<!-- Here I grab the image from the post with that tag -->  
<?php endwhile;  ?>
<?php wp_reset_query();?>

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

share|improve this answer
    
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 '13 at 8:31
3  
@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. –  helgatheviking Mar 14 '13 at 12:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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