
Hello. I was able to successfully set up ACF to create and save post titles using the ACF v4. However, this is not working when I switched to v5.
This is the code that worked in v4:
// Create Post
add_filter('acf/pre_save_post' , 'create_universe_form' );
function create_universe_form( $post_id ) {
// bail early if not a new post
if( $post_id !== 'new_universe' ) {
return $post_id;
}
// vars
$title = $_POST['fields']['field_590cecb75ba1b'];
// Create a new post
$post = array(
'post_status' => 'publish',
'post_type' => 'universe',
'post_title' => $title,
);
// insert the post
$post_id = wp_insert_post( $post );
// Update $_POST Return
$url = get_permalink($post_id);
$_POST['return'] = ($url);
// return the new ID
return $post_id;
}
I’m not sure what the differences are between v4 and v5 and if I need to change something. It was definitely working in v4 though. But now, in v5, it isn’t saving the post title nor the URL.
EDIT: Quick update, it IS working when I update an existing post. It’s only when **creating** a new post does it not save the title.
Hi @malachidraven
Thanks a lot for reaching out to us.
Is it possible that the field group ID changed during the migration?
Kindly try doing a var_dump of the $_POST and let me know how it goes.
Hope to hear from you soon.
I changed “[‘fields’]” to “[‘acf’]” and also updated the “[‘field_590cecb75ba1b’]” to the new ID. Somehow that made the URL work when creating a post, but it’s still not actually saving a title.
Hi @malachidraven
Kindly open a personalized support ticket as [email protected] so I may be able to debug the issue further.
Hope to hear from you soon.