I’m new in wp and I need to use wp_schedule_event.
I’m trying with this code

add_action( 'my_func', 'my_func');
function myFunction() {
  error_log("asd");
}

function activateSchedule($recurrence) {
  if(!wp_next_scheduled( 'my_func' )) {
    // Schedule the event
    wp_schedule_event(current_time('timestamp'), $recurrence, 'my_func' );
  }
}

I also create custom recurrences this way

function isa_add_cron_recurrence_interval( $schedules ) {

  $schedules['5sec'] = array(
        'interval'  => 5,
        'display'   => __( 'Every 5 seconds', 'textdomain' )
  );
}

add_filter( 'cron_schedules', 'isa_add_cron_recurrence_interval');

But the scheduled function runs only once.
What I’m missing?

Read more here: Scheduled event on wordpress runs only once


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: