Support » Plugin: Random Post on Refresh » How Is Random Determined

  • Resolved ironlion37

    (@ironlion37)


    Hi again, I’m curious how this plugin determines “random”. As I create new posts, I notice they are displayed much more frequently than older posts.

Viewing 5 replies - 1 through 5 (of 5 total)
  • ironlion37

    (@ironlion37)

    Update: yeah, the plugin consistently displays the last few posts I’ve created. I’m not seeing any older posts.

    Plugin Author Micah Wood

    (@woodent)

    @ironlion37

    So one of two things could be happening:

    1. The shortcode is configured by default to show images. As such, the plugin will only fetch posts that have images. If you have a small selection of posts with images, this could be the issue. Options if this is the case are to either add images to more posts, or configure the shortcode not to show images.

    2. The previous version of the plugin (1.0) had a bug related to the number of posts it would pull from when selecting a random post. The collection of posts from which the random post was selected was only as large as the number of posts set to display on a single page. By default, this is 10… however, if you set this to 1, your random post would never change. In order to prevent this, the code was updated to select from the 100 most recent matches given the shortcode parameters. Updating to version 1.1 of the plugin should fix this issue.

    ironlion37

    (@ironlion37)

    Thanks Micah. I just updated and immediately see an improvement. I think the way I’m using this is probably unusual, but it works great. I’m at 99 posts so far and plan on creating at least hundreds. Would it be relatively simple for me to edit the code to have it pull from say 500 recent posts, or just “all”?

    Plugin Author Micah Wood

    (@woodent)

    I was considering making that value editable via the shortcode. Ultimately, 100 was chosen because it provides enough randomness without compromising on performance. Querying large numbers of posts in a non-cacheable fashion isn’t a good idea.

    But you can find the code that controls that here: https://plugins.trac.wordpress.org/browser/random-post-on-refresh/trunk/RandomPostOnRefresh.php#L145

    ironlion37

    (@ironlion37)

    Thanks Micah! Very helpful. For my use case, slow queries are a non-issue.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How Is Random Determined’ is closed to new replies.