You do not need to use the post_meta
here, as all the Information is available in posts
.
To insert a new post, use wp_insert_post( $post )
, and pass the arguments to your $post
-array. This function can return a WP_Error
-object for Error handling (if the second argument is set to true
, returns 0 on error if false), and returns the ID
of the inserted post.
See the full list of arguments for wp_insert_post()
on the Codex.
$post = array(
'post_content' => $content, // The content you want to have set in the content
'post_title' => $title, // The title of your post.
'post_status' => 'publish', // Whatever status you want to have
'post_type' => 'your_custom_post_type' // the slug of your custom post type
);
$thisid = wp_insert_post( $post, true ); // insert the post and allow WP_Error object
if ( is_wp_error( $thisid ) ) {
// Error handling
} else {
// the rest of your code, inserting metadata
update_post_meta( $thisid, 'your_meta_key', $your_meta_value );
}