Order of options

Forums › Forums › Search & Filter Pro › Order of options

Viewing 4 posts – 1 through 4 (of 4 total)
  • Anonymous
    #264977

    Hi There,

    Is there a way to randomly display recipes each time a visitor accesses the recipes page before any filtering has taken place? Rather than display them in the same oder they were posted.

    Regards,

    Trevor
    #265026

    It somewhat depends on the Display Results method you are using. We do offer the option to sort posts randomly, but the ‘random’ order that WordPress provides (which is what we use) is PER PAGE of results, thus some posts may (and likely will) be repeated on many pages. Each load of posts by infinite scroll is a ‘page’.

    This is how WordPress does it, sorry.

    In short, I would advise against it.

    Anonymous
    #272318

    You can achieve something close with this snippet in your functions.php, although the randomized order persists between sessions rather than visits. Source

    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;
    }
    Anonymous
    #272322

    Also, other order types will no longer work since they will be overridden.

Viewing 4 posts – 1 through 4 (of 4 total)

Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.