0

This question is an exact duplicate of:

how combine wp_insert_post and wp update_post_meta?

i need first insert post, then update post, let me know about example? i want sample for my future project

Thanks

marked as duplicate by Chip Bennett, fuxia Oct 22 '13 at 11:54

This question was marked as an exact duplicate of an existing question.

2

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));
  • thanks this corrected? $my_post = wp_insert_post (array( 'post_title' => $ff[0], 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'products', )); $new_p = wp_insert_post( $my_post ); wp_set_post_terms($new_p,$term_s_child->term_id,'phone'); update_post_meta($new_p, 'price', $ff[1]); – John Genry Oct 17 '13 at 15:20
  • NO. In your example you creating post (first instance of wp_insert_post with some arguments) - than you tring to create a new post with invalid argument (which is ID of previously creacted post)... next code line skipped. take a look to code reference - codex.wordpress.org/Function_Reference/wp_insert_post – Butuzov Oct 17 '13 at 15:25
  • as will be right then? I need after the creation of the post, update it – John Genry Oct 17 '13 at 15:50
  • so use wp_update_post (same arguments + post id (ID)) - see codex.wordpress.org/Function_Reference/wp_update_post – Butuzov Oct 17 '13 at 15:58
  • Oleg, please add explanations to your answer, not as a comment. Thanks. – kaiser Oct 22 '13 at 11:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.