The “next run” in wp crontrol plug in is not working

我们两清 提交于 2020-06-29 19:11:47

问题


I want to create a function which the function run in every 3 minute.

I use plugin wp-crontrol to create a cron job event.

I searched in Google and Stackoverflow, and the code in function.php is

// Add a new interval of 180 seconds
// See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
add_filter( 'cron_schedules', 'isa_add_every_three_minutes' );
function isa_add_every_three_minutes( $schedules ) {
    $schedules['every_three_minutes'] = array(
            'interval'  => 180,
            'display'   => __( 'Every 3 Minutes', 'textdomain' )
    );
    return $schedules;
}

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

// Hook into that action that'll fire every three minutes
add_action( 'isa_add_every_three_minutes', 'every_three_minutes_event_func' );
function every_three_minutes_event_func() {
    // The code run update in every 3 minutes
    $update= get_field('ls_home_number_candidates');
    $updatePlusOne= $update++;
    update_post_meta(56, 'ls_home_number_candidates', $updatePlusOne);
}
?>

Then in my WP-Cron Events appears the new event called isa_add_every_three_minutes

But the event does not run. If I press "Run now", it's will appear a announce like "Successfully executed the cron event isa_add_every_three_minutes."

But it's not work and the field Next Run is always "now"

Please help. Thank you


回答1:


The function isa_add_every_three_minutes in your code is just to get the custom schedules you set, it's not related to the cron name. Your add_action should have the cron name, and the cron function you want to execute, and then you need to call it, so something like:

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

// Hook into that action that'll fire every three minutes
add_action( 'my_cron', 'every_three_minutes_event_func' );

Everything else looks fine on the surface.



来源:https://stackoverflow.com/questions/48747650/the-next-run-in-wp-crontrol-plug-in-is-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!