Wordpress - wp_insert_post() or similar for custom post type
From the Codex:
wp_insert_post() will fill out a default list of these but the user is required to provide the title and content otherwise the database write will fail.
$id = wp_insert_post(array(
'post_title'=>'random',
'post_type'=>'custom_post',
'post_content'=>'demo text'
));
It can be done using the following code :-
To enter a new post for a custom type
$post_id = wp_insert_post(array (
'post_type' => 'your_post_type',
'post_title' => $your_title,
'post_content' => $your_content,
'post_status' => 'publish',
'comment_status' => 'closed', // if you prefer
'ping_status' => 'closed', // if you prefer
));
After inserting the post, a post id will be returned by the above function. Now if you want to enter any post meta information w.r.t this post then following code snippet can be used.
if ($post_id) {
// insert post meta
add_post_meta($post_id, '_your_custom_1', $custom1);
add_post_meta($post_id, '_your_custom_2', $custom2);
add_post_meta($post_id, '_your_custom_3', $custom3);
}