Random post order, only if new visit

  • Hi,
    I have a tourism site that has lots of listings. I these have showing in a random order, primarily to avoid penalizing attraction/places that are either lower down the alphabet, or were originally published at a much earlier date.

    Is there a way to randomise the order, but keep the same order for at least the same visit?
    Or have it randomly assign for a set duration, ie 1 week?

  • Hi there,

    If you’re using a Query block, you can simply add a Random parameter to the query settings.

    However, for the other requirement – keeping the same randomized order for a set duration across new visits, that would require a custom solution and unfortunately that falls outside our support scope.

    Just a heads-up: some servers disable random ordering because it can be one of the most expensive query operations to run. For that reason, some hosts turn it off by default at the server level.

    So if the Random parameter doesn’t seem to work, that could be the reason.

  • Thanks Alvind,
    My server doesn’t disable it but it is definitely adding to the load which is maximising out resources. Which is why I’d like to limit it in some way, but I’d hate to remove it for the reasons noted.

    I understand why you can’t help. As far as your (technically) aware is this possible? Thanks!

  • Hi there,

    Yes, it’s definitely possible — just not something we can build out for you here.

    The general approach would be to generate a randomized order once (e.g. using a seed or by shuffling and storing the result), cache it with a transient or similar mechanism, and then serve that cached order for a set duration before regenerating. That way you get the fairness of randomization without hitting the database with ORDER BY RAND() on every page load — which would also solve your server resource concerns.

    You could hook into the query using the generateblocks_query_wp_query_args filter (if you’re using a GenerateBlocks Query Loop version 2) or pre_get_posts to implement this.

  • Huge thanks George. Thats much appreciated, help me to get a quote on it!

  • No problem!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.