[resolved] How to add four WP Queries without duplicate posts (7 posts)

  1. Pritam
    Posted 5 years ago #


    I want to have four separate WP queries on index.php without any duplicate posts. How can we do that?


  2. Pritam
    Posted 5 years ago #

    So far I have come across tuts that tell you how to have two queries without duplicate posts. I want four.

  3. Michael
    Forum Moderator
    Posted 5 years ago #

    just keep repeating the 'do_not_duplicate' array method in each loop:


    mainly after this line: 'Note for Multiple Posts in the First Category'

    rough layout:

    query for loop1
    $do_not_duplicate[] = $post->ID;
    end loop1;
    query for loop2 including 'post__not_in => $do_not_duplicate'
    $do_not_duplicate[] = $post->ID;
    end loop2;
    query for loop3 including 'post__not_in => $do_not_duplicate'
    $do_not_duplicate[] = $post->ID;
    end loop3;
    query for loop4 including 'post__not_in => $do_not_duplicate'
    end loop4;
  4. Pritam
    Posted 5 years ago #

    Thanks for pointing me in the right direction.
    I was using 'post__not_in' => array($post->ID,$exclude_ids),
    argument instead of 'post__not_in' => $exclude_ids,
    Now it's working fine.

  5. Alkorr
    Posted 5 years ago #

    Hi there, alchymyth! I tried to use this function but it doesn't work for me. I'm using the code provided by MichaelH on this thread (displaying 5 latest post title on the main content) and my goal is that if an article is posted in two categories (Books + Movies), then once it is displayed on the first one (Books), then on the second one (Movies), it won't show; the next article from that category will be displayed instead.

    I'm not good at PHP, nothing new here but I always search and try everything I can. Now I'm stuck...

    Thanks for you help!

  6. Michael
    Forum Moderator
    Posted 5 years ago #

    code by MichaelH extended with 'do_not_duplicate'

    (no guarantee, untested)

  7. Alkorr
    Posted 5 years ago #

    OMG it works!! Thank you so much alchymyth. You made my day! :)

Topic Closed

This topic has been closed to new replies.

About this Topic