2020 Update:
In case you landed here looking for a refresher on how to update the post’s meta, as I did, see the following edit:
The post array argument in wp_insert_post()
takes an inner array called meta_input
, so you can create the post with proper meta in one database query.
$page_id = wp_insert_post(array(
'post_title' => 'Team',
'menu_order' => '2',
'post_content' => '[team]',
'post_type' => 'page',
'post_parent' => 1,
'post_status' => 'publish',
'meta_input' => array(
'your_meta_key' => 'your meta value'
),
));
The same can be done for wp_update_post()
:
wp_update_post(array(
'post_title' => 'About',
'ID' => $page_id,
'meta_input' => array(
'your_meta_key' => 'your meta value'
),
));
Original Answer:
is this code enough for you?
/*
** wp_insert_post - http://codex.wordpress.org/Function_Reference/wp_insert_post
** function will create a new post and return a $interger shich is a ID of the new created post.
*/
$page_id = wp_insert_post(array(
'post_title' => 'Team',
'menu_order' => '2',
'post_content' => '[team]',
'post_type' => 'page',
'post_parent' => 1,
'post_status' => 'publish',
));
/*
** wp_update_post - http://codex.wordpress.org/Function_Reference/wp_update_post
** function is simular (actually its almost alias) of wp_insert_post
** it will update a post
** $arguments that passed to wp_update_post is a same as in wp_insert_post but require additional argument ID whish is id of the post
*/
wp_update_post(array('post_title' => 'About', 'ID' => $page_id));