Do not duplicate post covering 2 queries
-
Hi! I wonder if it is possible to not duplicate a post using 2 different queries. I explain.
I first want to show the 4 latest posts. Then I want to show the latest posts from each category. I’ve found a way (thanks to alchymyth) not to have duplicated post within the query showing the latest posts from each category. But the posts listed in my 4 latest posts query are duplicated in the latest posts list from each category. Logical.
Now I try to find a way to avoid that. I tried to put this code before the first query (showing the 4 latest posts):
<?php $my_query = new WP_Query('posts_per_page=4'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;?>
And close it after the query for the latest posts from each category:
<?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?> <?php endwhile; endif; ?>
But it doesn’t work.
It may sound complicated but I’m sure I’m not the only one looking for a solution about these duplicated posts on the home page.
Thanks for your help! ??
- The topic ‘Do not duplicate post covering 2 queries’ is closed to new replies.