0
$postdate = '2010-02-23 18:57:33';   
$postData = array(
   'post_title' => $attachment->post_title,
   'post_type' => 'post',
   'post_content' => $image_tag . $attachment->post_title,
   'post_category' => array('0'),
   'post_status' => 'publish',
   'post_date' => $postdate
);
$post_id = wp_insert_post($postData);

After adding post_date, new post is not creating anymore

1 Answer 1

1

Your code is correct. I have tested it and it works. I think what you are missing, and what I have missed while testing (banged my head against the wall for this mistake) is the fact that these posts do not show up at the top of your post list.

Remember, by default, that posts are sorted and ordered according to post date, the newest posts showing up first, the oldest post last. These new posts are not new posts, but counts as old posts according to their post date. So, with this in mind, you will need to go through your post list and look for these posts.

If you need to test if a post is inserted, dump $post_id. This should return a post ID

$postdate = '2014-02-23 18:57:33';   
$postData = array(
    'post_title' => $attachment->post_title,
    'post_type' => 'post',
    'post_content' => $image_tag . $attachment->post_title,
    'post_category' => array('0'),
    'post_status' => 'publish',
    'post_date' => $postdate
);
$post_id = wp_insert_post($postData);
?><pre><?php var_dump($post_id); ?></pre><?php  
3
  • still not inserting the new post :/
    – Hassan Ali
    Jan 13, 2015 at 7:51
  • See my update. You will be surprised :-) Jan 13, 2015 at 8:30
  • 2
    i want to kill myself yo were :D they are creating but the post are showing date wise. thanks alot
    – Hassan Ali
    Jan 13, 2015 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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