WP insert post PHP function and Custom Fields


The WordPress function is used for submitting data programatically. Standard fields to submit to incude the content, excerpt, title, date and many more.

What there is no documentation for is how to submit to a custom field. I know it is possible with the add_post_meta($post_id, $meta_key, $meta_value, $unique); function.

But, how to include that into the standard wp_insert_post function?

$my_post = array(
     'post_title' => $_SESSION['booking-form-title'],
     'post_date' => $_SESSION['cal_startdate'],
     'post_content' => 'This is my post.',
     'post_status' => 'publish',
     'post_type' => 'booking',
  wp_insert_post( $my_post );
Robin I Knight 4 months 0 Answers 18 views 0

Leave an answer