Hey @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 in the past.
Sorry I don’t have better news for you here. Cheers!
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 🙂
thanks for the extra info Hugh! Did not see that update myself, definitely helpful 🙂
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.