Gosh, thanks! That’s so clear. I think I removed the $post_id check based on another tutorial blog post, so the answer to my current issue wasn’t appearing to me. Now that you’ve told me, I realize it’s quite clear. Thanks so much for the help.
Thanks, Daniel. That’s really useful info which I’m sure I’ll use in the future.
However, right now I’m trying to do this through separate forms. That is, I have multiple forms on my site but they each update a different post-type.
This is in my functions.php:
// ACF SAVE NEW POST
function my_pre_save_post( $post_id )
{
// Create a new post
$post = array(
'post_status' => 'publish' ,
'post_title' => $_POST['fields']['field_52d978ea24ac7'],
'post_type' => 'location' ,
);
// insert the post
$post_id = wp_insert_post( $post );
// update $_POST['return']
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
This makes sense and works perfectly for one form — but if I add a second form to update a second post type, it doesn’t work. What do I need to modify so that I can have more than one form?
Cheers,
Enrico
Thanks for the response. Sorry for the confusion.
My post referred to this post:
http://support.advancedcustomfields.com/forums/topic/my-frontend-form-is-prefilled-with-previous-entries-all-the-time/
And your answer:
multiple pre_save_post
The trick here is to use the ‘html_after_fields’ arg to add in a hidden input with a custom value. This will get posted to the save action which you can then use to determine which form has been posted.
I’d like to know how to have multiple front-end forms that each create posts of different custom post types. Your response naveen009 suggested that the solution lies in the html_after_fields; but whatever the solution, I’d like to learn!
Thanks again for a great plugin.
Enrico
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.