Title: WP_Query loop problem
Last modified: August 19, 2016

---

# WP_Query loop problem

 *  Resolved [stevenybarra](https://wordpress.org/support/users/stevenybarra/)
 * (@stevenybarra)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/wp_query-loop-problem/)
 * i have my settings to show only 10 posts per page.
 * for a particular template tag, i wanted to show all the posts. i assumed and 
   went ahead and made another tag page with a new loop.
 *     ```
       <ol><?php $recent = new WP_Query("tag=2009&amp;showposts=40&amp;orderby=title&amp;order=ASC"); while($recent->have_posts()) : $recent->the_post();?>
       <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
       <?php endwhile; ?>
       </ol>
       ```
   
 * the loop works great, BUT i don’t know how to show ALL the posts; right now i’m
   only showing 40. is there a variable I can put that will show all?
 * my other question is i can’t figure out how to show an error message if no posts
   exist for that tag. (sorry, no posts matched your criteria)
 * i tried using
 *     ```
       <?php endwhile; else: ?>
   
       			<p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>
       			<p><?php posts_nav_link(' — ', __('&laquo; Previous Page'), __('Next Page &raquo;')); ?></p>
       ```
   
 * but i keep getting syntax errors.
 * any help is appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/wp_query-loop-problem/#post-1080163)
 * showposts=-1 will show all posts
 * if you use else you will need to put, before while($recent->have_posts()) , if(
   $recent->have_posts()) which the else will then match with
 *  Thread Starter [stevenybarra](https://wordpress.org/support/users/stevenybarra/)
 * (@stevenybarra)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/wp_query-loop-problem/#post-1080165)
 * thank you!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WP_Query loop problem’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [stevenybarra](https://wordpress.org/support/users/stevenybarra/)
 * Last activity: [16 years, 12 months ago](https://wordpress.org/support/topic/wp_query-loop-problem/#post-1080165)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
