I've searched everywhere for an answer to this question - since every paginated page is created anew, duplicate posts appear across pages. How do you prevent this? So that say three of the first 10 posts on page 1 aren't then repeated on page 2. This solution looks good:
Is it possible to paginate posts correctly that are random ordered?
But it doesn't work -- either on my main query or on a custom query I had written. It doesn't throw any errors, it just doesn't modify the query. This is how I implemented it in my functions.php file:
// randomize testimonials across pages
session_start();
add_filter('posts_orderby', 'edit_posts_orderby');
function edit_posts_orderby($orderby_statement) {
if(get_post_type() == 'testimonials') {
$seed = $_SESSION['seed'];
if (empty($seed)) {
$seed = rand();
$_SESSION['seed'] = $seed;
}
$orderby_statement = 'RAND('.$seed.')';
return $orderby_statement;
}
}
What am I doing wrong? In case it might help, this was my original query (I took out the orderby arg when I tried the function above):
query_posts('showposts=6');
$posts = get_posts ( array(
'post_type' => 'testimonials',
'orderby' => 'rand',
'meta_query' => array(
array(
'key' => '_testimonial_commercialresidential',
'value' => 'Residential') ),
) );
foreach ($posts as $post) : start_wp();
$do_not_duplicate = $post->ID;
static $count1 = 0; if ($count1 == "6") { break; } else { ?>
Thanks for your help!