Shit. After much fuss, my client has formally requested a Geodirectery replacement if I cannot resolve this issue in 1 week. I am willing to pay to get this sorted out (no pun intended).
Caching aside, I can disable that.
Can anyone shine some light on integrating this snippet?
<?php
session_start();
add_filter( 'posts_orderby', 'randomise_with_pagination' );
function randomise_with_pagination( $orderby ) {
if( is_front_page() ) {
// Reset seed on load of initial archive page
if( ! get_query_var( 'paged' ) || get_query_var( 'paged' ) == 0 || get_query_var( 'paged' ) == 1 ) {
if( isset( $_SESSION['seed'] ) ) {
unset( $_SESSION['seed'] );
}
}
// Get seed from session variable if it exists
$seed = false;
if( isset( $_SESSION['seed'] ) ) {
$seed = $_SESSION['seed'];
}
// Set new seed if none exists
if ( ! $seed ) {
$seed = rand();
$_SESSION['seed'] = $seed;
}
// Update ORDER BY clause to use seed
$orderby = 'RAND(' . $seed . ')';
}
return $orderby;
}
?>
I’m not sure how to call GD posts to replace if( is_front_page() ) {
Any help will be much appreciated.
Though, the author of this script mentioned:
Anyway – I thought I’d jump in here quickly to let you know that as of WordPress 4.5, that snippet in my post will be unnecessary (although it will still work of course). The reason for this is that in v4.5+ you will be able to specify a seed value for the random ordering from directly within the WP_Query args. So you can set your orderby parameter to look like this: rand(123) (where ‘123’ is your seed value) – that will achieve the same results as the solution in my post, but using much less code. You’ll still need to use the session to store the seed value, but you won’t need to use the posts_orderby filter anymore. Pretty neat!