0

I am using wp_schedule_event for Insert data every 1 Minutes in a teble. But here is some confusion where i have to add code for Insert. Here is my code which add in functions.php in my theme.

register_activation_hook(__FILE__, 'my_activation');
add_action('my_hourly_event', 'do_this_hourly');
function my_activation() {
    wp_schedule_event(time(), 'minutes', 'my_hourly_event');

        global $wpdb;
       //INSERT INTO `wp_test`.`wp_options` (`option_id`, `option_name`, `option_value`, `autoload`) VALUES (NULL, 'database_options', 'hello', 'yes');
}

function do_this_hourly() {
     $schedules['every_three_minutes'] = array(
            'interval'  => 60,
            'display'   => __( 'Every 1 Minutes', 'textdomain' )
        );

    return $schedules;
} 

//deactive
register_deactivation_hook(__FILE__, 'my_deactivation');
function my_deactivation() {
    wp_clear_scheduled_hook('my_hourly_event');
}
0

First you can to create a schedule for one minute, then bind function with that hook.

function add_new_intervals($schedules) 
{
    // add weekly and monthly intervals
    $schedules['every_single_minutes'] = array(
        'interval' => 60,
        'display' => __('Every Minute')
    );
    return $schedules;
}
add_filter( 'cron_schedules', 'add_new_intervals');

// To schedule event for this minute event
wp_schedule_event( current_time( 'timestamp' ), 'every_single_minutes', 'my_every_minute_event');

//add_action('my_every_minute_event', '_Func_to_execute_');

check this quick reference for details

Thanks

0

your cron must be register at the plugin or theme activation. Try wp crontol plugin to verify and run your cron task. But, i think you call "minutes" interval where you might call "every_three_minutes" interval for the schedule event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.