Reputation: 654
Here is my script, to let you know I use it inside my test file
$my_post = array(
'post_title' => "post test",
'post_date' => current_time('mysql'),
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(1)
);
$post_id= wp_insert_post($my_post);
var_dump($post_id);
Upvotes: 1
Views: 1592
Reputation: 16
Try to remove status param or change it to another status but not publish
Upvotes: 0
Reputation: 37
First check the query by using following line of code under wp_insert_post call:
exit(var_dump( $wpdb->last_query));
the query will be displaying if you run the code... try to execute the same code in phpmyadmin sql panel or any other db tool.. you will get to know the error.
Upvotes: 1
Reputation: 136
I think your date format is incorrect so please use this code
$my_post = array(
'post_title' => "post test",
'post_date' => date('y-m-d H:i:s'),
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(1)
);
$post_id= wp_insert_post($my_post);
var_dump($post_id);
Upvotes: 1