Update: yeah, the plugin consistently displays the last few posts I’ve created. I’m not seeing any older posts.
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.
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”?
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
Thanks Micah! Very helpful. For my use case, slow queries are a non-issue.