Forums › Forums › Search & Filter Pro › random order displaying duplicate results
- This topic has 4 replies, 3 voices, and was last updated 8 years, 11 months ago by
Ross.
-
Anonymous(Private) May 4, 2016 at 6:51 pm #44722
I have the ‘search and filter pro’ on my site.
Under the settings I have set:
Settings & Defaults -> posts -> default order -> random order.
This is showing random results on the first page, and also a new lot of random results on the second page (and any subsequent pages).
However, it does not remember which results were shown on the first page and so can show some of the same on the second page and then some results are also not displayed at all. Each page shows a random list of resutls not taking into account other pages from the search results.
You can see this on my site on http://gethelpisrael.com/therapist/I want to show a random lists of results but how do I make it remember the results have already been show on previous pages?
Ross Moderator(Private) May 5, 2016 at 1:18 pm #44763Hey Rena
For all our queries, we use the fantastic WP_Query (its kind of compulsory).
This means when we sort, we use the WP functions available – and the rand order your mention is part of WP – https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
Unfortunately, what you have noticed is the way WP handles the rand order – as soon as the page is refreshed, the results are again randomized – so you may see duplicates.
There is nothing we can do at this time – the only suggestion I can make is to add a custom field to your posts – something like
post_order
and then you can order your results by this key.You would have to of course assign a numerical value, randomly to each post – and its probably not exactly what you were after.
Thanks
Anonymous(Private) May 17, 2016 at 8:16 am #45712I have seen a function that claims to work but I can’t actually get it to work.
Should this code be compatible with this plugin? Do you know why it isn’t working?
session_start();
add_filter(‘posts_orderby’, ‘edit_posts_orderby’);
function edit_posts_orderby($orderby_statement) {
if( !is_admin() ) {
$seed = $_SESSION[‘seed’];
if (empty($seed)) {
$seed = rand();
$_SESSION[‘seed’] = $seed;
}$orderby_statement = ‘RAND(‘.$seed.’)’;
}
return $orderby_statement;
}Ross Moderator(Private) May 19, 2016 at 7:32 pm #46054Hey Rena
This filter should indeed be able to modify S&F queries, however I cannot guarantee that this code is good or working as I’ve never tested it.
If you have issues, they could be related to your usage of
$_SESSION
– I know WP discourages its use and I’ve seen some quite hacky workarounds to get it working.Saying all that, we have a filter in S&F, which allows you to order your post IDs in any order you want – I guess you combine the
seed
above with this filter – an explanation of it is in this post:https://support.searchandfilter.com/forums/topic/use-post__in-for-orderby-is-not-working/#post-45230
Thanks
-
AuthorPosts