I think I gave you the wrong code. I’m sorry about that. Please try this one instead:
// create the update data holder $vbs_post = array(); $vbs_post['ID'] = $post_id; $vbs_post['post_title'] = $new_title;
If you want to change the post slug, please try this code:
$vbs_post['post_name'] = 'this-is-the-new-slug';
Please check this page for more parameters: https://developer.wordpress.org/reference/functions/wp_insert_post/.
Also, please don’t forget to save the changes like this:
//Unhook function to prevent infitnite looping remove_action('acf/save_post', 'vbs_post_title_updater', 20); // Update the post into the database wp_update_post( $vbs_post ); //Rehook function to prevent infitnite looping add_filter('acf/save_post', 'vbs_post_title_updater', 20);
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!
© 2022 Advanced Custom Fields.