Forum Replies Created
-
AuthorPosts
-
rharriganMemberI found the issue. The two fields with scope ‘post’ where creating to objects – one with an ID and one without (class-piklist-form.php 2942-2968). The object with an ID saved as a revision post (accounting for one of the two posts). The object without an ID went to wp_insert_post. The foreach on 2991 is responsible. I got around this by deleting one of the ‘post’ fields and adding ‘object_id’ => $id
$id = get_the_ID(); // Where to save this form piklist('field', array( 'type' => 'hidden' ,'scope' => 'post' ,'object_id' => ($id ? $id : null) ,'field' => 'post_type' ,'value' => 'custom_post_type_1' )); /* // New post ID piklist('field', array( 'type' => 'hidden' ,'scope' => 'post' ,'object_id' => ($id ? $id : null) ,'field' => 'ID' ,'value' => ($id ? $id : '') )); */It seems to be working on my end. Please let me know if I’m doing anything wrong. If not, I’ll address the other related posts:
– https://piklist.com/support/topic/front-end-form-update-a-cpt/
– https://piklist.com/support/topic/frontend-forms-in-template-files/
rharriganMemberI’m sorry, I don’t understand what you are saying. I am now using
add_action( 'piklist_save_field-post', 'my_grab_new_post_id' ); function my_grab_new_post_id ( $fields ) { global $my_new_post_id; $my_new_post_id = $fields['ID']['object_id']; } add_filter( 'wp_redirect', 'my_stick_new_post_id_in_redirect', 10, 2 ); function my_stick_new_post_id_in_redirect ( $location, $status ) { global $my_new_post_id; return( $location."?_post[ID]=$my_new_post_id" ); }in my functions.php but I the redirect is not doing anything and I am still creating two posts. What code should I use to implement the example URL you supplied?
Best,
Ryan
rharriganMemberThanks @Steve, but I didn’t see anything in that file regarding saving to an already created CPT. I fixed the dependency issue (LayersWP and Piklist weren’t playing nice in this special circumstance), so that’s no problem anymore.
Now, I have another problem. Using the code I provided earlier:
$id = get_the_ID(); // Where to save this form piklist('field', array( 'type' => 'hidden' ,'scope' => 'post' ,'field' => 'post_type' ,'value' => 'custom_post_type_1' )); // New post ID piklist('field', array( 'type' => 'hidden' ,'scope' => 'post' ,'field' => 'ID' ,'value' => ($id ? $id : '') ,'required' => false, ));Piklist not only creates a new post (which I don’t want), but it creates ANOTHER new post with the meta from my specified post (from $id). When I submit, I now create two posts.
If it helps, I found this in class-piklist-form.php on line 3392:
$id = isset($object['ID']) ? wp_update_post($object) : wp_insert_post($object);How do I save the post meta on the front-end of the post I want to update?
Thanks,
Ryan
-
AuthorPosts