Support » Themes and Templates » How to add four WP Queries without duplicate posts

  • Resolved Pritam



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


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


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



    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;


    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.

    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!

    code by MichaelH extended with ‘do_not_duplicate’

    (no guarantee, untested)

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to add four WP Queries without duplicate posts’ is closed to new replies.