Forums Forums Search & Filter Pro random order displaying duplicate results

Viewing 5 posts - 1 through 5 (of 5 total)
  • Anonymous
    #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?

    Trevor
    #44748

    I am not sure what the issue here is, so I have marked this for the developer, Ross, to look at.

    Ross Moderator
    #44763

    Hey 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
    #45712

    I 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
    #46054

    Hey 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

Viewing 5 posts - 1 through 5 (of 5 total)