I want to schedule a cron job in Wp3.5.1 to sending email to those customer whose appointment is pending.
here some code am trying:
For the testing am scheduling corn for each second to insert row in table.
// insert row every second
add_action('wp', 'my_activation');
function my_activation() {
if ( !wp_next_scheduled( 'my_event' ) ) {
wp_schedule_event( time(), 'hourly', 'my_event');
}
}
add_action('my_event', 'do_this_event');
function do_this_event() {
global $wpdb;
$wpdb->query("INSERT INTO `wordpress-testing`.`wp_test` (`id`, `text`) VALUES (NULL, 'b');");
}
wp_get_schedules('my_event');
//custom recurrence
add_filter( 'cron_schedules', 'cron_add_every_sec' );
function cron_add_every_sec( $schedules ) {
$schedules['hourly'] = array(
'interval' => 1,
'display' => __( 'Do Secondly' )
);
return $schedules;
}
May am going wrong to do this. So please help me through.
Is cron run automatically after activation once OR its need to recurring visit after scheduled time past?