Title: Exclude duplicated posts
Last modified: August 19, 2016

---

# Exclude duplicated posts

 *  Resolved [simonebiffi](https://wordpress.org/support/users/simonebiffi/)
 * (@simonebiffi)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/exclude-duplicated-posts/)
 * Hi there,
 * I am trying to find a way to allow posts listings (and related images) to identify
   which post is being loaded and hence exclude it from being duplicated on the 
   same page. This way if you have a thumbs listing of your most recent articles,
   let’s say on the sidebar, you exclude the one that you are currently reading 
   to prevent it from being redundant on the page.
 * In my functions.php I have the following code:
 *     ```
       $included_pic = array();
   
       $pic_childs = get_categories('child_of='.$chic['category_2_id']);
   
       foreach($pic_childs as $pic_child) {
       array_push($included_pic, $pic_child->cat_ID);
       }
   
       array_push($excluded, $chic['category_2_id']);
       array_push($included_pic, $chic['category_2_id']);
       ```
   
 * where _$chic[‘category\_2\_id’]_ simply retrieves the category ID already provided
   in a config.inc file.
 * On the post file I then include this to load the article, making sure it is identified
   and hence excluded from being duplicated elsewhere on the same page:
 *     ```
       <?php global $included_pic; $showpost = new WP_query(); $showpost->query(array('category__in'=>$included_pic,'post__not_in'=>array($post->ID),'showposts'=>3)); ?>
       <?php if ($showpost->have_posts()) : ?>
       <?php while ($showpost->have_posts()) : $showpost->the_post();  ?>
       ```
   
 * The problem here is that such function only allows me to target the precise category_2
   in a situation where there would be plenty more categories to apply this to. 
   If I were to replicate the same code for each of the categories, I would find
   myself with a huge replicated function, simply unnecessary and extremely heavy
   to load.
 * Would someone know how to streamline the above code in order for the function
   to identify immediately at loading in which category I am each time a new post
   is loaded, and hence automatically get the category ID?
 * Hope someone can help.
    Thanks in advance. S.

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

 *  [monkeymynd](https://wordpress.org/support/users/monkeymynd/)
 * (@monkeymynd)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/exclude-duplicated-posts/#post-1210132)
 * Look here and search on $do_not_duplicate.
 * [http://codex.wordpress.org/The_Loop](http://codex.wordpress.org/The_Loop)
 *  Thread Starter [simonebiffi](https://wordpress.org/support/users/simonebiffi/)
 * (@simonebiffi)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/exclude-duplicated-posts/#post-1210176)
 * That worked just PERFECTLY!! Sweet and easy!
 * Thanks, Monkeymynd, much appreciated.
 *  [monkeymynd](https://wordpress.org/support/users/monkeymynd/)
 * (@monkeymynd)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/exclude-duplicated-posts/#post-1210180)
 * Glad you got it worked out 🙂

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

The topic ‘Exclude duplicated posts’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [category id](https://wordpress.org/support/topic-tag/category-id/)
 * [duplicate posts](https://wordpress.org/support/topic-tag/duplicate-posts/)
 * [exclude post](https://wordpress.org/support/topic-tag/exclude-post/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [monkeymynd](https://wordpress.org/support/users/monkeymynd/)
 * Last activity: [16 years, 8 months ago](https://wordpress.org/support/topic/exclude-duplicated-posts/#post-1210180)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
