Title: do not duplicate posts from widgets
Last modified: August 19, 2016

---

# do not duplicate posts from widgets

 *  [coreybrook1977](https://wordpress.org/support/users/coreybrook1977/)
 * (@coreybrook1977)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/do-not-duplicate-posts-from-widgets/)
 * I have put my main loop into a widget. I also put a feature slider and feature
   posts displayed in boxes, both with options to decide which category to set as
   feature. My problem is that when all of these widgets are displayed on the same
   page, I don’t want the posts to be duplicated in the main loop.
 * I am aware that I have to declare a global variable and assign post IDs to that
   variable in an array, but I am not doing it right, apparently.
 * **Here is the code for the feature slider loop:**
 *     ```
       global $themename_do_not_duplicate;
       	$themename_do_not_duplicate = array();
       	$arr = array();
       	$i=1;
       	$width = $instance['ImgWidth'];
       	$height = $instance['ImgHeight'];
       	$cat_posts = new WP_Query("showposts=" . $instance["featuredNum"] . "&cat=" . $instance["cat"]);
       	while ($cat_posts->have_posts()) : $cat_posts->the_post() $themename_do_not_duplicate[] = $posts->ID;?>
       				<li><a href="<?php the_permalink();?>">
       				<?php
       				$post_title = get_the_title();
       				$thumbnail = get_thumbnail($width,$height,'thumb',$post_title,$post_title);
       				$thumb = $thumbnail["thumb"];
       				print_thumbnail($thumb, $thumbnail["use_timthumb"], $post_title, $width, $height, 'thumb'); ?></a>
       				<div class="title">
       				<h2><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>
       				</div>
       				</li>
       		<?php endwhile; wp_reset_query();	?>
       ```
   
 * **Here is the loop for the feature boxes, which has four loops:**
 *     ```
       <?php query_posts("showposts=1&cat=".get_catId($instance['catOption4']));
       				  while (have_posts()) : the_post(); $themename_do_not_duplicate[] = $post->ID;?>
       ...stufff
                   <?php endwhile; wp_reset_query(); ?>
       ```
   
 *  Do I have to put the `global themename_do_not_duplicate` before each loop here
   or can I just put it in the beginning of the widget?
 * **Here is the main loop:**
 *     ```
       <?php global $themename_do_not_duplicate;
       if ($instance['NoRepeatPost'] == 1) {$arrgs=array('posts_per_page'=>$instance['postNum'],'post__not_in' => $themename_do_not_duplicate,'paged'=>$paged,);}
       else {$arrgs=array('posts_per_page'=>$instance['postNum'],'paged'=>$paged,);}
       query_posts($arrgs);
       if(have_posts()) : while (have_posts()) : the_post();$themename_do_not_duplicate[] = $post->ID; //begin the loop ?>
       ...stuff
       <?php endif;wp_reset_query(); //and so ends the loop ?>
       ```
   
 * In the top of the header.php file I put `global themename_do_not_duplicate`
 * I hope I explained my problem thoroughly.

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

 *  [bspr3663](https://wordpress.org/support/users/bspr3663/)
 * (@bspr3663)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/do-not-duplicate-posts-from-widgets/#post-1908702)
 * I would like to know how to do this also. Any help would be much appreciated.
 *  [bspr3663](https://wordpress.org/support/users/bspr3663/)
 * (@bspr3663)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/do-not-duplicate-posts-from-widgets/#post-1908703)
 * So I was able to figure it out with the help of [Elegant Themes](http://www.elegantthemes.com/affiliates/idevaffiliate.php?id=4603),
   who I need to mention, because I can’t take credit for this work.
 * I have a featured slider, here is it’s code:
    _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * I have a left sidebar of posts that do not duplicated with the featured slider.
   Once the posts is done with the slider it will then move down to the left sidebar.
   Here is the code:
    _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * The finished product is here: [http://www.boisestatepublicradio.org](http://www.boisestatepublicradio.org)

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

The topic ‘do not duplicate posts from widgets’ is closed to new replies.

## Tags

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

 * 2 replies
 * 2 participants
 * Last reply from: [bspr3663](https://wordpress.org/support/users/bspr3663/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/do-not-duplicate-posts-from-widgets/#post-1908703)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
