Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The scenario is to run insert_post function every midnight (00:00) of local time. Must run daily on weekday.

function add_daily_task(){
    if((date('l', time()) != 'Saturday') || (date('l', time()) != 'Sunday')){ 
        // insert post
    }
}

if(!wp_next_scheduled( 'add_daily_task_schedule')){
    wp_schedule_event(time(), 'daily', 'add_daily_task_schedule');
    // how should change time() to meet my local schedule?
}

add_action('add_daily_task_schedule', 'add_daily_task'); 
share|improve this question

2 Answers

The function:

time()

gives the UNIX timestamp in the GMT timezone.

So if you are GMT+2 you can use:

time() + 2*60*60;

or if you are GMT-4 you can use:

time() - 4*60*60;

Try replacing time() with mytime() in your code, where:

function mytime(){
    $gmt_offset_in_hours=-2; // for GMT-2 (EDIT this value) 
    return time() + $gmt_offset_in_hours*60*60;     
}
share|improve this answer

Not sure what is the question, but the use of time() is wrong as it will give you at best the local time of the server and not the local time of the site which takes into consideration the time zone configuration of WordPress.

The function that you should use is current_time.

share|improve this answer

Your Answer

 
discard

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.