WordPress insert post programmatically

WordPress have function wp_insert_post() which can be used to create posts programmatically. this function returns a ID by using which we can add custom fields to that post.

global $user_ID;
$new_post = array(
'post_title' => 'Post title which created using wp_insert_post()',
'post_content' => 'This is content of the post',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
$post_id = wp_insert_post($new_post);


Leave a Reply

Your email address will not be published. Required fields are marked *