Random Sorting With Short Intervals

Tested on local install

I found that transients don't work good on short intervals, probably because WP_Cron doesn't clean them up quick enough, so I use options.

add_filter( 'geodir_rand_seed', function() {

    // Option 1: will always change unless queries are made within the same second.
    // return time();

    // Option 2: set a time interval
   $unit = 60; // Hours: 3600;
   $interval = 2; // change here the interval.
   $rand_seed = get_option( 'geodir_rand_seed_fast', 0 );

   if ( time() > $rand_seed + ( $interval * $unit ) ) {
       $rand_seed = time();
       update_option( 'geodir_rand_seed_fast', $rand_seed );
    }
    return absint( $rand_seed );
}, 99, 0 );
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.