WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm scheduling a job in wp cron:

add_action('my_cron_hook', 'my_cron_action');
wp_schedule_event( time(), 'interval1', 'my_cron_hook' ); 

function my_cron_action(){
    //do something

The variable interval1 is set by the admin in another part of the code.
Also, there is a switch that lets the admin enable or disable the wp crop job.

My problem is this:
my_cron_action is executed as soon as it is scheduled
(this means, as soon as the admin enables the cron job from the backend).

What i want to do is this:
if we suppose that the time that the admin enabled the job is T,
i want the job to be run at T+interval1 for the first time, and not at T.

The next thing i want after this is done, is to create a button "Execute job now" that will run the job as soon as it's clicked.

share|improve this question
up vote 1 down vote accepted

As described in wp_schedule_event first parameter is $timestamp - the first time that you want the event to occur. So just add interval to $timestamp. I think it should be like

wp_schedule_event( time() + $delay, 'interval1', 'my_cron_hook' ); 

And set $delay as miliseconds before hook starts.

share|improve this answer
Good point! missed that, thanx! – dimitris Apr 14 '13 at 16:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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