I tried to create a new post using front end form, everything work exempt that I can’t get post title field value or post content field value 🙁
here is my code in the template page file:
function add_person( $post_id )
// check if this is to be a new post
if( $post_id != ‘new’ )
// Create a new post
$post = array(
‘post_status’ => ‘publish’ ,
‘post_type’ => ‘company’ ,
‘post_title’ => $_POST[‘acf’][“acf[_post_title]”],
‘post_content’ => $_POST[‘acf’][“acf[_post_content]”]
// 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
add_filter(‘acf/pre_save_post’ , ‘add_person’ );
$args = array(
‘post_id’ => ‘new’,
‘field_groups’ => array(24),
‘post_title’ => true,
‘post_content’ => true
acf_form( $args );
when I vardump the $POST variable I get NULL
Also I didn’t understand how to utilise functions like “function add_person( $post_id ) » in function.php how to add several functions like this one ?
ex: – function add_person( $post_id )
– function add_company( $post_id )
– function add_product( $post_id )
and how to setup my template files so they know which function they have to use according to the post type they are supposed to create ?
Thank you very much for your help
I’ve also noticed that ACF support has been less reliable in the last few months. It’s possible that Elliot has received a sudden influx of users since the launch of ACF 5 and figuring out how to adapt. Fortunately, he’s still pushing out new features.
I’m not sure if this will completely answer your questions, but here’s a start. Here’s how I think you need to setup your function call:
acf_form( array( 'post_id' => 'new_post', 'new_post' => array( 'post_type' => 'company', 'post_status' => 'publish', ), 'field_groups' => array(24), 'post_title' => true, 'post_content' => true, ) );
You’d call that in your template file with
acf_form_head called at the top (above
get_header). No need to mess with actions or filters in your functions.php file unless you want to do further customization.
You must be logged in to reply to this topic.
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!
Plugin boilerplates can do some of the heavy lifting during initial development. We look at four options to speed up your plugin creation. https://t.co/ZtMsdBxAHw— Advanced Custom Fields (@wp_acf) June 5, 2023
© 2023 Advanced Custom Fields.