Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Help Scheduling Annual Event for Exact Date WordPress

  • REFUNDED

Need some help scheduling an event for specific time. I am using Cron View to keep an eye on what is in Cron but I can't seem to get this added.

add_action('my_yearly_event', 'do_this_on_june_thirty');

function my_activation_2() {
wp_schedule_event( 1372636740, 'yearly', 'my_yearly_event');
}
add_action('wp', 'my_activation_2');

function do_this_on_june_thirty() { //Stuff
}


I think I am not scheduling properly, I need it to fire once with a plugin activation or something.. not sure

(I added the yearly interval to schedule)

Answers (2)

2013-02-28

John Cotton answers:



function my_activation() {
if ( !wp_next_scheduled( 'my_annual_event' ) ) {
wp_schedule_event( time(), 'annually', 'my_annual_event');
}
}
register_activation_hook(__FILE__, 'my_activation');

function do_this_annually() {
// do something once a year
}
add_action('my_annual_event', 'do_this_annually');


function my_corn_schedules(){
return array(
'annually' => array(
'interval' => 60 * 60 * 24 * 365,
'display' => 'Once a year'
)
);
}
add_filter( 'cron_schedules', 'my_corn_schedules');


Kyle comments:

Hi John, I already added the schedule. This will add the event for now (judging by the time() .. needs to be June 30 like above)

Schedule:
function my_add_intervals($schedules) {
$schedules['yearly'] = array(
'interval' => 31557600,
'display' => __('Once Yearly')
);
return $schedules;
}
add_filter( 'cron_schedules', 'my_add_intervals');


Is the only other change this:

add_action('wp', 'my_activation_2');

to

register_activation_hook(__FILE__, 'my_activation_2');


Kyle comments:

The register_activation_hook broke my site, I have not used that before so I may have done something wrong

2013-02-28

Arnav Joy answers:

using yearly event you can fire it once in a year , so what is the problem , you can test it using 'hourly ' option and then if everything is ok then you can change it to yearly


Kyle comments:

Agreed, I guess I didn't explain my problem right. Even with changing it to time() and hourly nothing is added to cron so I am wondering what is wrong