Title: Multiple Loops duplicate post question
Last modified: August 20, 2016

---

# Multiple Loops duplicate post question

 *  Resolved [JoostJoost](https://wordpress.org/support/users/joostjoost/)
 * (@joostjoost)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/multiple-loops-duplicate-post-question/)
 * Hi
 * In total I want to display 4 posts in which I created 2 loops where the goal 
   of the first loop is to show the 2 latest posts.
    The second loop should display
   2 posts random, excluding the first 2 of above. This works fine except for one
   thing:
 * Instead of displaying 2 posts the second loop leaves the space empty if it selects
   one post from the first loop. Who can help me solve this issue?
 * This is my code:
 *     ```
       <div id="vids">
       		<?php $my_query = new WP_Query('cat=-3,-6&posts_per_page=2&orderby=date&order=DESC');?>
       		<?php while ($my_query->have_posts()) : $my_query->the_post();
   
        $do_not_duplicate[] = $post->ID ?>
   
       	<div class="homevideo">
       	<div class="category">
       	<?php the_category(' '); ?>
       	</div>
       	<div class="videothumb">
       	<img src="<?php video_thumbnail(); ?>" width="185" height="105" />
       	</div>
       	<div class="videoname">
             <a href="<?php the_permalink() ?>" > <?php the_title(); ?>  </a>
           </div>
               </div>
       		<?php endwhile; ?>
       		<?php $my_newquery = new WP_Query('cat=-3,-6&posts_per_page=2&orderby=rand');?>
       <?php while ($my_newquery->have_posts()) : $my_newquery->the_post();
   
       if (in_array($post->ID, $do_not_duplicate)) continue;
        ?>
       	<div class="homevideo">
       	<div class="category">
       	<?php the_category(' '); ?>
       	</div>
       	<div class="videothumb">
       	<img src="<?php video_thumbnail(); ?>" width="185" height="105" />
       	</div>
       	<div class="videoname">
             <a href="<?php the_permalink() ?>" > <?php the_title(); ?>  </a>
           </div>
               </div>
   
       		 <?php endwhile; ?>
       <?php wp_reset_query(); ?>
       ```
   
 * thanks a lot in advance!
 * Joost

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

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/multiple-loops-duplicate-post-question/#post-3118725)
 * Take out the if test for in_array, and put the excluded post ids in the query:
 *     ```
       <?php
       $args = array(
          'cat' => '-3,-6',
          'posts_per_page' => 2,
          'orderby' => 'rand',
          'post__not_in' => $do_not_duplicate
       );
       $my_newquery = new WP_Query($args);?>
       ```
   
 *  Thread Starter [JoostJoost](https://wordpress.org/support/users/joostjoost/)
 * (@joostjoost)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/multiple-loops-duplicate-post-question/#post-3118727)
 * Thank you so much. It works perfectly!
 * Topic resolved!

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

The topic ‘Multiple Loops duplicate post question’ 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: [JoostJoost](https://wordpress.org/support/users/joostjoost/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/multiple-loops-duplicate-post-question/#post-3118727)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
