Is it possible to paginate posts correctly that are random ordered?
You can generate a random number on the first page load then store it in a SESSION variable and use that as the $seed for further paginated requests.
If you are trying to acheive this on your main loop for instance, you could add the following to your functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
session_start(); add_filter('posts_orderby', 'edit_posts_orderby'); function edit_posts_orderby($orderby_statement) { $seed = $_SESSION['seed']; if (empty($seed)) { $seed = rand(); $_SESSION['seed'] = $seed; } $orderby_statement = 'RAND('.$seed.')'; return $orderby_statement; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.