Using add_post_meta in form not creating custom meta after form submits
-
I have a form which i’ve modified that includes two fields that should use add_post_meta but are not working. I’ve used the code from this answer on stack exchange https://wordpress.stackexchange.com/a/11289/10413 that works. It create a post with tags and all the fields you see.
I then found this tutorial which had some sample code for adding post meta https://www.odharma.com/2011/01/how-to-create-data-entry-forms-for-wordpress-with-contactform7/
My code is below which is not working, the post is created but not the meta data from the two form fields I added
$new_post = array( 'post_title' => $title, 'post_content' => $description, 'post_category' => array($_POST['cat']), // Usable for custom taxonomies too 'tags_input' => array($tags), 'post_status' => 'publish', // Choose: publish, preview, future, draft, etc. 'post_type' => 'website' //'post',page' or use a custom post type if you want to ); add_post_meta($new_post, 'custom1', $new_post['field-custom1']); add_post_meta($new_post, 'custom2', $new_post['field-custom2']);
The two custom fields are called custom1 and custom2. How can I get these to post with the form?
Thanks
- The topic ‘Using add_post_meta in form not creating custom meta after form submits’ is closed to new replies.