Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a lot of posts everyday to publish. Now, I am thinking to schedule all those posts which I saved them as drafts. So, I tried to make a custom post scheduler. Here is what I tried,

$time = strtotime('+5 min');  

$args = array('post_type' => 'post','post_status' => 'draft');                  
$draft_posts = get_posts( $args );

foreach($draft_posts as $posts) {
$my_post = array(
      'ID'           => $posts->ID,
      'post_date'    => date('Y-m-d H:i:s', $time),
      'post_status'  => 'future');
$my_post->edit_date = true;
wp_update_post( $my_post );
$time += 5400;                                   // every 1.5 hr
}

As soon as I run this, all drafts are published instantly at same time, rather than an interval of 1.5 hr. Can anyone please tell where is the problem?

share|improve this question
    
There is option on post at the backend wordpress dashboard from where you can publish posts the option is publish on there you can set the date and time for the post to publish –  Vikas Gautam Sep 17 '13 at 11:46
    
I have around 100-125 posts, so it would be difficult for all to perform what you told. –  busyjax Sep 17 '13 at 11:48
    
you need to use jquery to show posts after some time gape but that is other way to delay the post post will publish at same time this way but not display on front end before the given time by jquery. –  Vikas Gautam Sep 17 '13 at 11:52
2  
@Vickey you can schedule posts in this way. By setting a future date WordPress will label it 'scheduled' and it will be published after that date. busyjax, however, WordPress' "cron job" handling is not precise, and so batches of posts may be published together rather than every 90 minutes. That can be fixed using a genuine cron-job. –  Stephen Harris Sep 17 '13 at 11:57

1 Answer 1

up vote 0 down vote accepted

You're treating $my_post as an array, and then an object. Try moving 'edit_date' into the array.

Also keep in mind that 'post_date' should be in your blog's timezone. date will give the date-time in UTC timezone. See date_i18n() (codex: http://codex.wordpress.org/Function_Reference/date_i18n).

From what I can see, everything else is corret.

share|improve this answer
    
Thanks Stephen, after playing, I found that same you pointed about edit date. –  busyjax Sep 17 '13 at 13:19

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.