Title: Random sort order even with pagination
Last modified: August 31, 2016

---

# Random sort order even with pagination

 *  Resolved [killerdog](https://wordpress.org/support/users/killerdog/)
 * (@killerdog)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/random-12/)
 * First off, great plugin! Very useful indeed. Thanks for making it available!
 * So, [@jtree5757](https://wordpress.org/support/users/jtree5757/) previously mentioned
   in this forum, that the random products feature isn’t working correctly with 
   pagination, since it resets at every new page. Which means customers won’t effectively
   be able to see all products using this sort mode unless pagination is avoided.
   This has effected us as well.
 * Couldn’t this be fixed by utilizing the user’s unique session id as a randomize
   key? Or, maybe by passing a randomize key as a user cookie? This way, the randomized
   product list is static for the full user session, and automatically reset when
   a new session is created later on.
 * Just my ten cents here, as we really love the idea of using the random product
   list, even with pagination! Thanks again!
 * [https://wordpress.org/plugins/woocommerce-extra-product-sorting-options/](https://wordpress.org/plugins/woocommerce-extra-product-sorting-options/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Contributor [Beka Rice](https://wordpress.org/support/users/bekarice/)
 * (@bekarice)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/random-12/#post-7151485)
 * Hey [@killerdog](https://wordpress.org/support/users/killerdog/), you could definitely
   work pagination if you used a seed for each user. However, as this plugin using
   the built in WooCommerce filters for sorting options, it’s pretty limited in 
   what we can do aside from passing in a custom sorting argument, and thus randomized
   sorting pagination can’t be implemented here. This was intended originally for
   small product catalogs.
 * For the regular WordPress sorting filters, the entire WP Query object is passed
   into filters, so you can modify it to seed & randomize items. With WooCommerce,
   we’re using a pre-built query and filtering only its arguments, so we can’t really
   do this in a simple way.
 * If you wanted to do this with a customized bit of code, you could replace the
   WooCommerce sorting dropdown completely yourself and use your own query for randomized
   sorting, I’ve found [this tutorial helpful](http://hughlashbrooke.com/2013/08/22/wordpress-random-post-order-with-correct-pagination/)
   in the past.
 * Sorry I don’t have better news for you here. Cheers!
 *  [Hugh Lashbrooke](https://wordpress.org/support/users/hlashbrooke/)
 * (@hlashbrooke)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/random-12/#post-7151488)
 * Hey there – I got notified about this because you linked to my blog – thanks 
   Beka! 🙂
 * Anyway – I thought I’d jump in here quickly to let you know that as of WordPress
   4.5, that snippet in my post will be unnecessary (although it will still work
   of course). The reason for this is that in v4.5+ you will be able to specify 
   a `seed` value for the random ordering from directly within the `WP_Query` args.
   So you can set your `orderby` parameter to look like this: `rand(123)` (where‘
   123’ is your `seed` value) – that will achieve the same results as the solution
   in my post, but using much less code. You’ll still need to use the session to
   store the `seed` value, but you won’t need to use the `posts_orderby` filter 
   anymore. Pretty neat!
 * And that concludes your friendly WordPress tip for the day 🙂
 *  Plugin Contributor [Beka Rice](https://wordpress.org/support/users/bekarice/)
 * (@bekarice)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/random-12/#post-7151624)
 * thanks for the extra info Hugh! Did not see that update myself, definitely helpful
   🙂
 *  [Alex Seidanis](https://wordpress.org/support/users/beerallica/)
 * (@beerallica)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/random-12/#post-8375816)
 * Hi all and thanks Hugh for this awesome (and much needed) contribution. I’m chiming
   in to add a little something to this. In my case, I wanted to have a random order
   that would change every day, but would remain the same within each given day.
   So, the solution to this (combined with Hugh’s contribution) would be `'orderby'
   => 'rand('.date('Ymd').')'`. I this scenario, there’s no need to store anything
   to the session cookie.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Random sort order even with pagination’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-extra-product-sorting-options/assets/icon-256x256.
   png?rev=3303778)
 * [Extra Product Sorting Options for WooCommerce](https://wordpress.org/plugins/woocommerce-extra-product-sorting-options/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-extra-product-sorting-options/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-extra-product-sorting-options/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-extra-product-sorting-options/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-extra-product-sorting-options/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-extra-product-sorting-options/reviews/)

## Tags

 * [session](https://wordpress.org/support/topic-tag/session/)

 * 4 replies
 * 4 participants
 * Last reply from: [Alex Seidanis](https://wordpress.org/support/users/beerallica/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/random-12/#post-8375816)
 * Status: resolved