Random Pagination within Categories
-
Hi,
I’m trying to get my posts to display randomly with infinite pagination, and within their category. I’ve tried the following code:
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; }Which displayed posts in a “random” order within their category, or for the homepage all posts – but it was the same random order.
For example, when activating this code it displays the posts for say the gardening category as: B, A, D, C. And no matter if you refresh or open a new tab, it will always be in this order. While for the category books it might display the posts as: X, U, W, Z, but again will stick with this “random” order for its category.
Does anyone have any ideas on what I can try? Other codes I’ve given a go seem to duplicate posts, or can’t recognise categories. This is the closest I’ve got so far, but obviously a locked random order is no longer random if it stays the same.
Thank you in advance for any help.
The topic ‘Random Pagination within Categories’ is closed to new replies.