WordPress wp_schedule_event not triggering

I am attempting to create a scheduler that looks for a trigger every five minutes.

When I initialize the plugin, I get an initial response, but I’m not getting the trigger every five minutes like I’m trying to accomplish. Here’s my code:

Read More
add_filter('cron_schedules', 'add_scheduled_interval');

function add_scheduled_interval($schedules) {
    $schedules['minutes_5'] = array('interval'=>300, 'display'=>'Once 5 minutes');
    return $schedules;
    global $schedules;
  }
if (!wp_next_scheduled('sms_cron')) {
    wp_schedule_event(time(), 'minutes_5', 'sms_cron');
    }

add_action('sms_cron', 'send_text_alerts');

function send_text_alerts() {
    //My function
    }

My question is, what am I missing? Anything obvious jumping out? Thanks in advance!

Related posts

Leave a Reply

1 comment

  1. you need to add the following to an action:

    if (!wp_next_scheduled('sms_cron')) {
    wp_schedule_event(time(), 'minutes_5', 'sms_cron');
    }
    

    so something like this:

    add_action( 'wp', 'setup_schedule' );
    function setup_schedule() {
    if (!wp_next_scheduled('sms_cron')) {
    wp_schedule_event(time(), 'minutes_5', 'sms_cron');
    }
    }