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.
Read more here: wp_query orderby random do not repeat infinite scroll – one loop