Home › Forums › General Issues › Using acf_form – add post title… › Reply To: Using acf_form – add post title…
Worked this out. @greenhoe hope this helps.
// Create the frontend form
function my_pre_save_post( $post_id ) {
if ( $post_id != 'new' ) {
return $post_id;
}
$post = array(
'post_status' => 'draft',
'post_title' => $_POST['fields']['field_5344021b6851b'],
'post_type' => 'events'
);
$post_id = wp_insert_post($post);
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
Now ACF allows a $_POST variable to be used for the title but does not really state how to use it. We create a title field in ACF and then used the field name that was automatically generated from ACF. So, as above:
'post_title' => $_POST['fields']['field_5344021b6851b'],
field_5344021b6851b
is the name of my title field I created.
Hope this helps. Worked for me. Let me know if you have any problems.
-R
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.