Getting Three Loops NOT to Duplicate
-
I have learned how to have multiple loops by reading the Codex and searching the forums, and have learned also how to prevent the post from duplicating in the second loop. However, I have three loops and can’t seem to get the PHP syntax correct to prevent duplicates from both of first two loops.
Here’s what I have going on. In the first loop, I am pulling one post from the “featured” category. In the second loop, I am pulling one post from the “latest” category. In the third loop, I am trying to display the remaining posts except the ones that have already been posted in the first two loops. This is sort of working, the third loop is only duplicating a post from one of the first two loops. Maybe seeing the loops will help explain.
The first loop:
<?php $my_query = new WP_Query('category_name=featured&showposts=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate1 = $post->ID; ?>
The second loop:
<?php $my_query = new WP_Query('category_name=latest&showposts=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate2 = $post->ID; ?>
The third loop:
<?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate1 ) continue; update_post_caches($posts); ?>
As you can see above, I’ve named the do_not_duplicate values differently in the first and second queries. My problem is that I don’t know the correct syntax to specify both of these in the third query. I realize this is a lack of PHP knowledge on my part, and I’ve been trying all kinds of different things, but I haven’t figured it out yet.
If any of you would be so kind as to help, I would be very grateful. Thanks for any help you can provide:)
- The topic ‘Getting Three Loops NOT to Duplicate’ is closed to new replies.