Home › Forums › Front-end Issues › Multiple acf_form's on one Page › Reply To: Multiple acf_form's on one Page
Hi SaskiaB! I solved it by adding a hidden input field to the form.
So in my page:
$bio_args = array(
'post_id' => 'new_artist',
'field_groups' => array( 55 ),
'submit_value' => 'Submit my Bio',
// 'return' =>
'html_after_fields' => '<input type="hidden" name="post_type" value="frp_artist">'
);
?>
<?php acf_form( $bio_args ); ?>
Then in my functions:
function wnc_bio_frontend( $post_id )
{
// check if this is to be a new post
if( $post_id != 'new_artist' )
{ return $post_id; }
// Create a new post
$tax_actors = array(
$_POST['fields']['field_5439adfebbbcb'],
);
$post = array(
'post_status' => 'pending',
'post_title' => $_POST['fields']['field_5439aa052a606'],
'post_type' => $_POST['post_type'],
'tax_input' => $tax_actors,
);
// 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' , 'wnc_bio_frontend' );
Notice the “post type” hidden field. I hope that helps!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.