wp_schedule_event not firing

2019-01-26 13:37发布

问题:

I'm trying to schedule an event inside a theme's functions.php but i cannot get it to "fire". I'm using the Cron View plugin and it shows the event scheduled correctly but nothing happend when is time to execute

This is my code

    if ( ! wp_next_scheduled( 'prefix_hourly_event' ) ) {
        wp_schedule_event( time(), 'hourly', 'prefixhourlyevent');       
    }

    add_action( 'prefixhourlyevent', 'prefix_do_this_hourly' );

    function prefix_do_this_hourly() {       
       wp_mail('myemail@gmail.com','Cron is working', 'Cron is working: ','','');
    }

回答1:

You can manually run WordPress cron jobs by going to http://www.example.com/wp-cron.php?doing_cron. This is where you will be able to see any errors that your scripts creates, really useful when debugging wp scheduled tasks.



标签: php wordpress