Proper formatting of post_date for wp_insert_post?

If you don’t add a post_date then WordPress fills it automatically with the current date and time.

To set another date and time [ Y-m-d H:i:s ] is the right structure. An example below with your code.

$postdate="2010-02-23 18:57:33";

$new_post = array(
   'post_title'    =>   $title,
   'post_content'  =>   $description,
   'post_date'     =>   $postdate,
   'post_status'   =>   'publish',
   'post_parent'   =>   $parent_id,
   'post_author'   =>   get_current_user_id(),
);

//SAVE THE POST
$pid = wp_insert_post($new_post);

Leave a Comment