wp_insert_post and add_post_meta
-
So I built a form for people to post their own stories on my blog, it works well the post gets added as expected, however I ran into some trouble trying to add custom fields to the post. Here is my code (the important stuff anyways):
$newPost = array( 'post_content' => $STORY, //The full text of the post. 'post_parent' => 1426, //Sets the parent of the new post. 'post_status' => 'pending', //Set the status of the new post. 'post_title' => $TITLE, //The title of your post. 'post_type' => 'post', //Sometimes you want to post a page. 'comment_status' => 'closed', // 'closed' means no comments 'post_category' => $STORY_CAT, //Add some categories.. 'post_name' => $SLUG ); $post_id = wp_insert_post($newPost); add_post_meta($post_id, 'emailAddress', $EMAILADDRESS); add_post_meta($post_id, 'displayName', $DISPLAYNAME);
Thanks for all your help, I love being a part of this growing community, I am a designer trying to keep up, so please bear with me.
- The topic ‘wp_insert_post and add_post_meta’ is closed to new replies.