I have 120 posts of one category ready for my wordpress blog. For the moment, posts are drafts and I don't want to schedule them manually.

I want to publish them like this:

  • 4 articles each day from the 1st of August 2013
  • 1 at 10am / 1 at 2pm / 1 at 5pm / 1 at 8:30pm

What I need is the SQL query to:

  • Update date_post for the 120 posts, based on the needs described above
  • Change "draft" mode to "pending"
  • The publication order is based on the creation date of the posts: the older will be the first published.

I'm lost in the queries and loops. If someone could help, it would be very very appreciated.

Thanks a lot,


  • Any particular articles at those times? Any four or your 120 drafts is ok on any one day? – s_ha_dum Jul 9 '13 at 14:11
  • any four of the 120 will be ok. – chris Jul 9 '13 at 20:00

I would not do this with SQL. A relatively simple PHP loop should work.

function bulk_schedule_posts_wpse_105834() {
  $args = (
      'cat' => 1,
      'posts_per_page' => -1,
      'post_status' => 'draft',
      'post_type' => 'post',
  $posts = new WP_Query($args);
  if (!$posts->have_posts()) return false;

  $date = '2013-08-01';
  $times = array(

  while ($posts->have_posts()) {

    global $post;

    if (0 !== $posts->current_post && 0 === $posts->current_post%4) {
      $date = date('Y-m-d',strtotime('+1 day',strtotime($date)));

    $thisdate = $date.' '.$times[$posts->current_post%4].':00';
    $date_gmt = get_gmt_from_date($thisdate);
    $post->edit_date = true;
    $post->post_date = $thisdate;
    $post->post_date_gmt = $date_gmt;
    $post->post_status = 'future';


Run that function once and then remove it.

What you are doing is moderately dangerous. Test that thoroughly on dummy data before using it on a live site. I don't think it should actually destroy much data but it could make a big mess.

Barely tested. Possibly buggy. Caveat emptor. No refunds.

  • Dear s_ha-dum, Thanks a lot for your help, I'll test it on a draft website before on the live stuff. It helps me a lot. I wish you a very pleasant day! – chris Jul 12 '13 at 5:17
  • Firsts tests are OK. Impressive. – chris Jul 12 '13 at 6:49
  • One more point: when you load the site with the script integrated to function.php, it's good to know that the page will be loaded after that every posts status are change. So it can take time depending on the number of drafts. – chris Jul 12 '13 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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