Home › Forums › General Issues › Frontend Form not populating right in backend › Reply To: Frontend Form not populating right in backend
With ACF PRO, you don’t need to use the acf/pre_save_post
hook and wp_insert_post()
function anymore. You can use the ‘new_post’ option and provide it with the wp_insert_post()‘s parameters instead. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/.
After that, you can change the title like this:
//Auto add and update Title field:
function my_post_title_updater( $post_id ) {
// get the church name
$new_title_church_name = get_field('curch_name_field', $post_id);
// get the selected date and the current date
$new_title_date = get_field('start_date', $post_id);
$new_title_current_date = new DateTime($new_title_date);
// set the title
$new_title = $new_title_church_name . ' - ' . $new_title_date . ' - ' . $new_title_date->format('M j, Y');
// create the update data holder
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['title'] = $new_title;
//Unhook function to prevent infitnite looping
remove_action('acf/save_post', 'my_post_title_updater', 20);
// Update the post into the database
wp_update_post( $my_post );
//Rehook function to prevent infitnite looping
add_filter('acf/save_post', 'my_post_title_updater', 20);
}
// run after ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'my_post_title_updater', 20);
I hope this 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.