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)