Title: Multiple loops, 2 Categories, All Posts
Last modified: August 19, 2016

---

# Multiple loops, 2 Categories, All Posts

 *  Resolved [VicePrez](https://wordpress.org/support/users/viceprez/)
 * (@viceprez)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/multiple-loops-2-categories-all-posts/)
 * Im having trouble with “multiple loops”. I read the codex on “the loop”, along
   with some others. Im really new to this, ive never built a website before, and
   im learning fairly quickly.
 * In essence, what i’m trying to do is the following:
 * Category X: List one post
 * Category Y: List one post
 * List all other posts, minus the two posts.
 * The idea behind this, is to list Category X and Y side by side, at the top of
   my page, then continue and have all my others posts (from all categories) listed
   below them. (the styling is complete, the PHP coding is what im having trouble
   with.
 * **This is what ive got so far for category X (featured)**
 * <?php $my_query = new WP_Query(‘category_name=featured&showposts=1’);
    while(
   $my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->
   ID; ?>
 * **and this is for Category X (news)**
 * <?php $my_query = new WP_Query(‘category_name=news&showposts=1’);
    while($my_query-
   >have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
 * Then i used this to post all my posts except for the other two, except it removes
   the post from category Y (news), and doesn’t remove the one from category X (
   featured)
 * <?php query_posts(array(‘post__not_in’=>array($do_not_duplicate)));
    if (have_posts()):
   while (have_posts()) : the_post();?>
 * I added the “array” in case i wanted to show more than one post and have both
   removed (as far as i understood from the one of the codex pages, nevertheless
   it works).
 * Ive spent the past 4-5 hrs digging and trying different types of things to get
   it to work. I just want those two posts removed from all my other posts, from
   all categories (including category X and Y)
 * Thanks in advance guys.

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

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/multiple-loops-2-categories-all-posts/#post-1913375)
 * try it with this for both `$do_not_duplicate = $post->ID;`.
 * `$do_not_duplicate[] = $post->ID;`
 *  Thread Starter [VicePrez](https://wordpress.org/support/users/viceprez/)
 * (@viceprez)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/multiple-loops-2-categories-all-posts/#post-1913409)
 * im sorry keesie, but that doesnt seem to work, i did notice something while trying
   that. Ill try to illustrate it.
 * **i pasted the following for Category X:**
 * $do_not_duplicate = $post->ID;
 * **and the following for Category Y:**
 * $do_not_duplicate[] = $post->ID
 * **and i kept the following for all my posts**
 * <?php query_posts(array(‘post__not_in’=>array($do_not_duplicate)));
    if (have_posts()):
   while (have_posts()) : the_post();?>
 * well, what i noticed is that when i did that, Category Y’s post shows up in *
   all my posts* and Category X’s post disappears, when it was the other way round
   before you gave me the new coding. I know now that at least the coding (for all
   my posts) reads whats being passed down from Category X.
 * any other suggestions? i think your on the right track.
    thanks again.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/multiple-loops-2-categories-all-posts/#post-1913441)
 * Do this for the first to loops `$do_not_duplicate[] = $post->ID;`
    and this for
   the third.
 *     ```
       <?php query_posts(array('post__not_in'=> $do_not_duplicate));
       if (have_posts()) : while (have_posts()) : the_post();?>
       ```
   
 *  Thread Starter [VicePrez](https://wordpress.org/support/users/viceprez/)
 * (@viceprez)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/multiple-loops-2-categories-all-posts/#post-1913443)
 * keesie that worked so elegantly. thanks alot.
 * if i dont mind asking, how does this variation differ from the original ones?
   whats so special about them:
 * **$do_not_duplicate[] = $post->ID **
 * vs.
 * **$do_not_duplicate = $post->ID **
 * ..?
 * by the way, thanks again, i can focus on other things now. your a life saver.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/multiple-loops-2-categories-all-posts/#post-1913444)
 * `$do_not_duplicate` is a variable and `$do_not_duplicate[]` becomes a numerically
   indexed array (so it can hold multiple values) when you pass a value to it.
 *  Thread Starter [VicePrez](https://wordpress.org/support/users/viceprez/)
 * (@viceprez)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/multiple-loops-2-categories-all-posts/#post-1913479)
 * oh, alright that makes alot of sense now.
 * by the way, thank you for your time. i really appreciate it.

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

The topic ‘Multiple loops, 2 Categories, All Posts’ is closed to new replies.

## Tags

 * [all posts](https://wordpress.org/support/topic-tag/all-posts/)
 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [multiple loops](https://wordpress.org/support/topic-tag/multiple-loops/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [VicePrez](https://wordpress.org/support/users/viceprez/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/multiple-loops-2-categories-all-posts/#post-1913479)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
