Hi Folks,
I have the following code in a template to create a user profile (this is for a job board). I have a CPT for user_profile and a field group set up for it. Everything is working (the profile is getting created and the fields are getting populated), but I would like to use the “name” field from my field group for the title of the post. I am unsure as to how to go about it. Would appreciate any help you can provide. Thanks.
<?php while ( have_posts() ) : the_post(); ?>
<?php acf_form(array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'user_profile',
'post_status' => 'publish'
),
'submit_value' => 'Create Your User Profile'
)); ?>
<?php endwhile; ?>
This needs to be done using either an acf/save_post filter https://www.advancedcustomfields.com/resources/acf-save_post/ or an acf/pre_save_post filter https://www.advancedcustomfields.com/resources/acf-pre_save_post/
In either case, in your filter you get the field and use wp_update_post() to update the title of the post https://codex.wordpress.org/Function_Reference/wp_update_post
There is an example of using acf/save_post here https://support.advancedcustomfields.com/forums/topic/set-post-title-from-field-group-toggle/ and you can probably find others