Skip Navigation

[Resolved] YEARS_FROM_NOW does not always refresh the 'onthisday' view

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 7 replies, has 2 voices.

Last updated by Christopher Amirian 1 year, 5 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2624015
Screenshot 2023-07-14 131456.png

Tell us what you are trying to do?
I am filtering a view, comparing a date field with YEARS_FROM_NOW() for the years 1892 to 1918.
I removed the page from the cache. (but the provider cannot take it out of the server cache)

When refreshing the page, the date filter does not update the search, meaning that the page stays on 'yesterday's date', instead of filtering on the date field.

The only way that works consistently to get it refreshed, is to go into WP and open the page in the editor, and update the page. After that, the 'on this day' page correctly filters 'today' and shows the events on this day.

When someone views the page for the first time, it works fine.

I simply go to the page each day and manually update it, but would like to have this automatic/automated.
Is there any documentation that you are following?
Toolset doc

Is there a similar example that we can see?
You would have to test this over several days, by simply going to hidden link and checking the events shown. Sometimes there are no events on a date, which makes it difficult to check the date; just re-test the next day until you have an event visible.

What is the link to your site?
This is the page: hidden link

#2624349

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

It seems to be a problem of cache and you will need to either turn off the cache for the page or somehow automate the page update.

The code below might help for the second scenario as I do not know enough about the first scenario.

// Schedule an action if it's not already scheduled
if (! wp_next_scheduled ( 'my_daily_page_touch' )) {
    wp_schedule_event(time(), 'daily', 'my_daily_page_touch');
}

// Hook into that action that'll fire daily
add_action('my_daily_page_touch', 'touch_page_daily');

function touch_page_daily() {
    // The ID of the page that you want to touch
    $page_id = 5975; // change this to your page ID

    // Get the current page data
    $page_data = get_post($page_id);

    // Make a minor change (update the modified date)
    $page_data->post_modified = current_time('mysql');
    $page_data->post_modified_gmt = current_time('mysql', 1);

    // Update the page without changing its last edit user
    wp_update_post($page_data, true);
}

This code sets up a daily WordPress cron job that updates the modification date of the page with the ID you specify.

From the front end of the website I think the page ID is 5975 but if not please change it in the code.

Please note that this code should be added to your theme's functions.php file or a custom plugin file.

Finally, this is just an extra step to help if we could do something about it but there is no guarantee of a working solution and the best one is to deacitvate cache for the page.

Thanks.

#2624359

The page has been removed from cache ages ago, but on the provider side it probably is still in the server cache, since they told me they cannot exclude one page.

I will try out your code, and come back to you. It takes a few days to test.

Very kind of you to provide the code snippit.

#2624379

Christopher Amirian
Supporter

Languages: English (English )

Thank you, we will wait for the result.

#2624973

The code works. Thank you.

Would it be possible to code it to update the page at one second past midnight every day? Because, what does 'daily' currently mean in the code? When is 'daily'?

#2625191

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

There is no control over that. You can use plugins such as the one below to control the schedule of the cron jobs:

https://wordpress.org/plugins/wp-crontrol/

Thanks.

#2625207

for some reason I cannot close this ticket.

Thanks for the great support!

Close ticket.

#2625361

Christopher Amirian
Supporter

Languages: English (English )

Sure thanks 🙂