• Resolved heisel

    (@heisel)


    Great and useful plugin! Well done.

    It looks like it shows the latest posts on the same day. Are you able to randomize this?

    So if you have posts written on the same day in 2020, 2019, 2018 and 2016, it does not only show the latest psots which would be the ones written in 2020 in this case.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Through the settings, you can choose to show posts from as many years back as you want. You can consequently show posts from 2020, 2019, 2018 and 2016 within one single widget.

    Thread Starter heisel

    (@heisel)

    it always shows the latest first, so it would always show 2020. I do not see any settings on how to change the order.

    On my website I have over 30,000 articles written over 18 years, so have several articles written on the same day throughout they years, but only shows the “newest” articles written on the day. Would be great if you are able to click randomize.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    it always shows the latest first, so it would always show 2020

    It does indeed. I can see how that could be a problem when you have a lot of posts published each day.

    You could use the following code snippet in a functionality plugin like this one to randomize the order each day:

    add_filter(
    	'jeherve_posts_on_this_day_query_args',
    	function ( $args ) {
    		$args['orderby'] = 'rand';
    		return $args;
    	}
    );

    However, it’s worth noting that the results are cached for a day, so the random order that’s pulled in the morning will be valid for the rest of the day.

    You could reduce the duration of the cache to something like 10 minutes, like so, however I must warn you that this may cause the page to load slower every time the cache has to get refreshed, depending on the amount of posts and years you’ve been publishing posts on your site:

    add_filter(
    	'jeherve_posts_on_this_day_cache_duration',
    	function () {
    		return 600; // 10 minutes, in seconds.
    	}
    );

    I hope this helps.

    Thread Starter heisel

    (@heisel)

    Thanks for the snippet and your help. I have inserted it now and will check out in the coming days ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Randomize results on the same day’ is closed to new replies.