I completed several cron jobs in Wordpress. First of all, I want to clean, I searched a lot for this problem, but did not find the exact solution. So, I posted here.
The problem is that one cron is running, but the other never starts, and I scheduled an interval every three hours for the first cron, but it sometimes runs several times for a minute to receive several emails. And others are never executed.
Does anyone provide a solution to perform two functions for updating a database at various fixed intervals through Wordpress Cron. Thank you very much in advance.
register_activation_hook(__FILE__, 'activate_one');
register_activation_hook(__FILE__, 'activate_two');
add_filter( 'cron_schedules', 'intervals_schedule' );
function intervals_schedule($schedules) {
$schedules['threehour'] = array(
'interval' => 10800,
'display' => __( 'Every 3 hours' )
);
$schedules['onehour'] = array(
'interval' => 3600,
'display' => __( 'Every 1 hour' )
);
return $schedules;
}
function activate_one() {
if (!wp_next_scheduled('cron_action_one')) {
wp_schedule_event( time(), 'threehour', 'cron_action_one');
}
}
add_action('cron_action_one', 'execute_one');
function execute_one()
{
}
function activate_two() {
if (!wp_next_scheduled('cron_action_two')) {
wp_schedule_event(time(), 'onehour', 'cron_action_two');
}
}
add_action('cron_action_two', 'execute_two');
function execute_two()
{
}