Last active
December 4, 2017 12:16
-
-
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()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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