Title: Second Loop not displaying all posts
Last modified: August 20, 2016

---

# Second Loop not displaying all posts

 *  Resolved [daboo](https://wordpress.org/support/users/daboo/)
 * (@daboo)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/second-loop-not-displaying-all-posts/)
 * Hey all. I have a secondary loop on some of my pages displaying posts of a specific
   category. This loop is currently displaying 10 of 18 posts in this category, 
   and I can’t figure out why. There is a counter in the loop to wrap each five 
   posts in a div, but so far it isn’t displaying more than two divs. Code for the
   secondary loop:
 *     ```
       query_posts('cat=8'); /* cat with 18 posts */
       $counter = 1;
       if (have_posts()) :
       	while (have_posts()) : the_post();
       	if ($counter == 1) { echo '<div class="licont" style="float:left;">'; } ?>
       		<div>
       			<span class="icon_sprite year_icon year_<?php echo the_time('Y'); ?>"></span>
       			<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('thumbnail') ?></a><br />
       			<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
       				<?php echo substr(preg_replace('/([^>]*)(\,|:)([^>]*)/', '$1', get_the_title()), 0, 21); ?>
       			</a>
       		</div>
       		<?php if ($counter == 5) { echo '</div>'; $counter = 1; } else { $counter++; } ?>
       	<?php endwhile; ?>
       <?php endif; ?>
       ```
   
 * Does anyone more familiar with the loop (or php) see where I went wrong? Presently
   this loop displays the ten most recently posts chronologically. Changing the 
   dates of the posts does change which posts are displayed, but not the number 
   which are displayed. Thanks in advance

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/second-loop-not-displaying-all-posts/#post-2677828)
 * if you don’t specify the number of posts, the number is possibly taken from the
   reading settings in the dashboard;
 * try:
 *     ```
       query_posts('cat=8&posts_per_page=-1'); /* cat with 18 posts */
       ```
   
 * [http://codex.wordpress.org/Class_Reference/WP_Query#Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Parameters)
 *  Thread Starter [daboo](https://wordpress.org/support/users/daboo/)
 * (@daboo)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/second-loop-not-displaying-all-posts/#post-2677884)
 * Dear Sir,
    You are a very clever man. I don’t know why that hadn’t crossed my
   mind, but that was exactly the problem. Thank you so much!

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

The topic ‘Second Loop not displaying all posts’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * 2 replies
 * 2 participants
 * Last reply from: [daboo](https://wordpress.org/support/users/daboo/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/second-loop-not-displaying-all-posts/#post-2677884)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
