How to execute wp_schedule_event event on custom time interval in wordpress

For add new time interval we need to first register it.

// Here i register for every two minutes

function add_every_two_minutes( $schedules ) {
    $schedules['every_two_minutes'] = array(
            'interval'  => 120,
            'display'   => __( 'Every 2 Minutes', 'textdomain' )
    );
     
    return $schedules;
}
add_filter( 'cron_schedules', 'add_every_two_minutes' );
Now we can use it as below

wp_schedule_event( time(), 'every_two_minutes', 'cron_function_for_execute' );
 

Comments

Popular posts from this blog

How to add image option in nav menu in wordpress

How to add a custom email functionality in woocommerce,wordpress for example new email template for shipping order

How to change user id on checkout page for assign order to different user in woocommerce wordpress