I have found a lot of documentation on solving this issue with multiple loops, I'm finding it hard to see a solution for one custom loop.
Problem: I'm using infinite scroll to load in the next page of posts to the homepage. The posts need to be shown in a random order so I need to store which posts have been shown and then exclude them the second time the query is hit.
<?php $my_query = new WP_Query(array('post__not_in'=> $do_not_duplicate,
'orderby' => 'rand',
'category_name' => 'projects',
'posts_per_page' => 20,
'paged' => $paged));
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<?php get_template_part( 'entry' ); ?>
<?php endwhile; ?>
I have built this from http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action - however the approach there is to use $do_not_duplicate
in the second loop.
Perhaps I need to shuffle this around a bit, store the posts shown in another way, a cookie? Any guidance appreciated.
$do_not_duplicate
to the current post's ID - for each post? Don't you want to keep track of all the posts already handled? I'd rather store the post IDs in an array (and then eventually implode it to get a comma separated string), or create that string by hand (meaning concatenating).$do_not_duplicate
variable will never be populated when it needs to be. You need to find a way to pass that information to the infinite scroll script. I don't see the WordPress specific part of this though. You have that part right, though usingpaged
makes no sense in this context.