WP CRON runs only the first time

OK, so I’ve tested your code and I’m pretty sure it can’t run even once… And here’s why… If you’ll take a look at wp_schedule_event you’ll see this check at the top of the function: if ( !isset( $schedules[$recurrence] ) ) return false; It means that you can’t schedule event with unknown recurrence. So let’s … Read more

Long running action from plugin

You could use WordPress’ pseudo-cron and wp_schedule_single_event. <?php // add the action. add_action(‘wpse71941_cron’, ‘wpse71941_long_running’); function wpse71941_long_running($args) { // might need to call `set_time_limit` here set_time_limit(0); // do long running stuff here // return normal time limit if($l = ini_get(‘max_execution_time’)) set_time_limit($l); } // schedule the event for right now wp_schedule_single_event( time(), ‘wpse71941_cron’, array(‘args’ => ‘for’, ‘callback’ … Read more

WP Cron and wp_insert_post

For those who stumble upon this later, use either option 1 or 2 found here: https://core.trac.wordpress.org/ticket/19373. “For other developers who run into this and need to work around it, either of these 2 options work: call wp_set_post_terms() to add your taxonomies after calling wp_insert_post() set up a “current user” in your script before calling wp_insert_post()”

How to correct schedule my event weekly with wp_schedule_event()

According to the docs for this function, you can’t set up a weekly event by default. wp_schedule_event(int $timestamp, string $recurrence, string $hook, $args = array() ); The $recurrence value needs to be one of: “hourly” “twicedaily” “daily” You’ll need to test today’s date inside your callback function, my_event. Something like: function my_event() { # date(‘l’) … Read more