- This topic has 6 replies, 3 voices, and was last updated 6 years, 1 month ago by
George.
-
AuthorPosts
-
-
December 11, 2015 at 7:40 pm #5305
GeorgeMemberHello,
I created a form in the front-end but it is not saving in the database.
<?php /* Title: Test Method: POST Logged in: true Message: Data saved. */ piklist('field', array( 'type' => 'text', 'scope' => 'post_meta', 'field' => 'test', 'label' => __('Test'), )); piklist('field', array( 'type' => 'submit', 'field' => 'submit', 'value' => 'Submit' ));After submission i get this notice:
Notice: Undefined index: post in \www\w\wp-content\plugins\piklist\includes\class-piklist-form.php on line 3028Am i missing something?
If i replace post_meta with user_meta it saves in the wp_usermeta table.The form is in a custom post type post?
Piklist version 0.9.9.7
Other plugins: WordPress Helpers. -
December 12, 2015 at 12:50 pm #5313
kabadabraMemberIf you’re saving to a CPT, be sure to add the following to the top of the form….
/* Title: Test Method: post Logged in: true Message: Data saved. */ /******* This section here is what you require ********/ // Where to save this form piklist('field', array( 'type' => 'hidden', 'scope' => 'post', 'field' => 'post_type', 'value' => 'custom_post_type_here' ) ); /***************/ piklist('field', array( 'type' => 'text', 'scope' => 'post_meta', 'field' => 'test', 'label' => __('Test'), )); // Rest of your form boxes.... piklist('field', array( 'type' => 'submit', 'field' => 'submit', 'value' => 'Submit' ));This defines which CPT to save to.
Hope this helps!
-
December 12, 2015 at 1:05 pm #5314
GeorgeMemberThank you.
That does save the value, but not for the post from where it was submitted,
instead it creates a new post (draft) and associates the meta value to it.Is it possible to save it for the current post and on resubmission it updates the value?
-
December 14, 2015 at 8:32 am #5322
kabadabraMemberI might not understand the above correctly, but I’m assuming you want the post to be set to published when created?
If so, add the following to your code:
// post_status piklist( 'field', array( 'scope' => 'post', 'type' => 'hidden', 'field' => 'post_status', 'value' => 'publish' ) ); -
December 14, 2015 at 11:38 am #5324
GeorgeMemberI mean the form is on a published post.
The form has a meta_key “test”, it should check if there is a meta_key “test” associated with the post the form is submitted from, if there is it updates its value, else it add a new row.
-
December 14, 2015 at 12:59 pm #5335
-
December 14, 2015 at 1:05 pm #5336
GeorgeMemberYes that’s it.
Thank you.
-
-
AuthorPosts
- The topic ‘Saving post meta from front-end not working’ is closed to new replies.