Mika MAtikainen

Apr 15, 2020 · 4 min read

How can I insert custom post type content programmatically in WordPress using PHP?


 'My new example post',
 'post_content' => 'My new content!',
 'post_status' => 'public',
 'post_type' => 'my_post_type'
);

$post_id = wp_insert_post( $new_post );

if( $post_id ){
 // Update custom field on the new post
 update_post_meta( $post_id, 'my_custom_field', 'Hello!' );
} else {
 echo "Error, post not inserted";
}
 

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This