I need to save the permalinks on a site a few times daily, and want to know if it’s possible to have this done automatically.
The Word Press function to flush permalinks is flush_rewrite_rules()
. Is it possible to get this function to run on its own on a timer? Once an hour?
I found this code here, but it does not work, and I do not understand how it would run every hour –
add_action('my_hourly_event', 'do_this_hourly');
function my_activation() {
if (!wp_next_scheduled('my_hourly_event')) {
wp_schedule_event(time(), 'hourly', 'my_hourly_event');
}
}
add_action('wp', 'my_activation');
function do_this_hourly() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}