List All wp-cron Scheduled Events

This returns an array of all scheduled WP cron events. For each cron event, it gives the hook name, the recurrence schedule, and the time interval in seconds.

_get_cron_array()

Example Usage

echo '
'; 

print_r( _get_cron_array() ); 
echo '
';

Run a wp_schedule_event Recurrence Every 3 Minutes

By default, wp_schedule_event lets you choose a recurrence interval of ‘hourly’, ‘twicedaily’, or ‘daily’ for WP Cron jobs. Here, I show you how to add a custom recurrence interval of 3 minutes.

You may want to run a WP Cron job every 3 minutes, or so, for testing purposes. To add an interval of 3 minutes to the WP Cron schedules, use this:

function isa_add_every_three_minutes( $schedules ) {

    $schedules['every_three_minutes'] = array(
            'interval'  => 180,
            'display'   => __( 'Every 3 Minutes', 'textdomain' )
    );
     
    return $schedules;
}
add_filter( 'cron_schedules', 'isa_add_every_three_minutes' );

Now, you can use ‘every_three_minutes’ as the recurrence parameter when you use wp_schedule_event:

wp_schedule_event( time(), 'every_three_minutes', 'your_cron_function' );

Scheduled Cron Job in wordpress

if (!wp_next_scheduled('my_task_hook')) {

    wp_schedule_event(time(), 'hourly', 'my_task_hook');


add_action('my_task_hook', 'my_task_function');

function my_task_function() {

    wp_mail('nileshyadav326@gmail.com', 'Automatic email', 'Automatic scheduled email from WordPress.');

}