のドキュメントを読むと、作成しwp_insert_post
た投稿の投稿IDが返されます。
それを次の関数__update_post_meta
(このサイトから取得して少し適合させたカスタム関数)と組み合わせた場合
/**
* Updates post meta for a post. It also automatically deletes or adds the value to field_name if specified
*
* @access protected
* @param integer The post ID for the post we're updating
* @param string The field we're updating/adding/deleting
* @param string [Optional] The value to update/add for field_name. If left blank, data will be deleted.
* @return void
*/
public function __update_post_meta( $post_id, $field_name, $value = '' )
{
if ( empty( $value ) OR ! $value )
{
delete_post_meta( $post_id, $field_name );
}
elseif ( ! get_post_meta( $post_id, $field_name ) )
{
add_post_meta( $post_id, $field_name, $value );
}
else
{
update_post_meta( $post_id, $field_name, $value );
}
}
次のものが得られます。
$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',
);
$the_post_id = wp_insert_post( $my_post );
__update_post_meta( $the_post_id, 'my-custom-field', 'my_custom_field_value' );