Skip to content

Instantly share code, notes, and snippets.

@IronGhost63
Last active December 4, 2017 12:16
Show Gist options
  • Save IronGhost63/c49fdf8b7b5da6596a3207d34dcbc41e to your computer and use it in GitHub Desktop.
Save IronGhost63/c49fdf8b7b5da6596a3207d34dcbc41e to your computer and use it in GitHub Desktop.
FacetWP Random Order with Preservation (use session_id as a seed instead of time()
<?php
// Original - https://facetwp.com/random-ordering-in-facetwp/
function preserve_random_order( $orderby ) {
if(session_id() == ""){
session_start();
}
$seed = session_id(); // use session_id as a seed
$orderby = str_replace( 'RAND()', "RAND('{$seed}')", $orderby );
return $orderby;
}
add_filter( 'posts_orderby', 'preserve_random_order' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment