Multiple Loops and Duplicate Post
-
Running into an issue. Everything works as expected, except when I use two loops on the home page with a do not duplicate array. All I want it to do, is to run the second loop, not the first, and to not duplicate any of the post ID’s stored in the array. With out the Ajax call, the logic works perfectly, but when I add the ajax call (click not scrolling) it repeats both loops, reseting the do not duplicate array, causing duplicate post. Please help.
This is the loop below, nearly identical to they way WP suggest to use multiple loops one one page:
<?php $my_query = new WP_Query( array( 'category__and' => array(23,2) )); while ( $my_query->have_posts() ) : $my_query->the_post(); $do_not_duplicate[] = $post->ID; ?> <?php get_template_part( 'parts/loop', 'archive-grid' ); ?> <?php endwhile; ?> <?php query_posts( array( 'post__not_in' => $do_not_duplicate, 'category__in' => array(2) )); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'parts/loop', 'archive-grid' ); ?> <?php endwhile; endif; ?>
Ajax Load More – Infinite Scroll works great. I’ve already recommended it to a few people, i just need to get past this one issue.
- The topic ‘Multiple Loops and Duplicate Post’ is closed to new replies.