Title: &quot;Featured posts&quot; changes the number shown
Last modified: August 21, 2016

---

# "Featured posts" changes the number shown

 *  Resolved [sideswipev2](https://wordpress.org/support/users/sideswipev2/)
 * (@sideswipev2)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/featured-posts-changes-the-number-shown/)
 * I’ve recently put together a website for a local golf club. The front page has
   2 sections for “featured posts” that show 3 posts each. The first shows latest
   posts to category A and only category A. The second set of featured posts shows
   ANY latest posts. I’ve added the ‘do not duplicate’ lines so there isn’t any 
   overlap.
 * I’m not phenomenal with php, but I hashed together the code from using the WordPress
   resources but for some reason the sections randomly have changed from 3 posts
   to 2 posts. Can anyone point me towards where I’m going wrong?
 * This is the code for the first set of featured posts that only show category 
   A.
 *     ```
       <?php $the_query = new WP_Query('category_name=frontpage&showposts=3'); ?>
           <?php while ($the_query -> have_posts()) : $the_query -> the_post();
           $do_not_duplicate[] = $post->ID;?>
   
           <li><a href="<?php the_permalink() ?>" rel="bookmark" ><?php the_post_thumbnail('homepage-post-thumbnail', array('class' => 'box-image', 'alt' => ''.get_the_title().'', 'title' => ''.get_the_title().'')); ?></a>
           <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
           <div class="content-ver-sep"></div>
           <p><?php the_excerpt(__('(more…)')); ?></p></li>
           <?php endwhile;?>
       ```
   
 * Here is the code for the second featured post section that shows any new posts.
 *     ```
       <?php if (have_posts('showposts=3')) : while (have_posts()) : the_post();
        if (in_array($post->ID, $do_not_duplicate)) continue;
        ?>
   
           <li><a href="<?php the_permalink() ?>" rel="bookmark" ><?php the_post_thumbnail('homepage-post-thumbnail', array('class' => 'box-image', 'alt' => ''.get_the_title().'', 'title' => ''.get_the_title().'')); ?></a>
           <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
           <div class="content-ver-sep"></div>
           <p><?php the_excerpt(__('(more…)')); ?></p></li>
           <?php endwhile; endif; ?>
       ```
   

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/featured-posts-changes-the-number-shown/#post-3737272)
 * [http://codex.wordpress.org/Function_Reference/have_posts](http://codex.wordpress.org/Function_Reference/have_posts)
 * try to use `WP_Query()` and the `'post__not_in'` parameter for the second loop;
   
   [http://codex.wordpress.org/Class_Reference/WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query)
 * see also the related section in [http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action](http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action)
   afer the headline ‘Note for Multiple Posts in the First Category’
 *  Thread Starter [sideswipev2](https://wordpress.org/support/users/sideswipev2/)
 * (@sideswipev2)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/featured-posts-changes-the-number-shown/#post-3737278)
 * Changed
 *     ```
       <?php if (have_posts('showposts=3')) : while (have_posts()) : the_post();
        if (in_array($post->ID, $do_not_duplicate)) continue;
        ?>
       ```
   
 * to
 *     ```
       <?php query_posts(array('post__not_in'=>$do_not_duplicate));
        if (have_posts()) : while (have_posts()) : the_post();
        ?>
       ```
   
 * Seems to have done the trick. Thanks a lot!

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

The topic ‘"Featured posts" changes the number shown’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [sideswipev2](https://wordpress.org/support/users/sideswipev2/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/featured-posts-changes-the-number-shown/#post-3737278)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
