PHP Snippet: WordPress/ACF Save Post Hook – Save Title
In order to have ACF save the concatenation of the author custom post type’s first name and last name as title, use the following.
add_action('acf/save_post', 'my_acf_save_post');
function my_acf_save_post($post_id)
{
if ($_POST['post_type'] != 'cpt-author')
return;
$Post_Title = '';
$Fields = get_fields($post_id);
$FirstName = $Fields['ACF-Author-FirstName'];
if (isset($FirstName)) {
$Post_Title = $FirstName . ' ';
}
$LastName = $Fields['ACF-Author-LastName'];
if (isset($LastName)) {
$Post_Title = $Post_Title . $LastName . ' ';
}
$post_update = array(
'ID' => $post_id,
'post_title' => $Post_Title
);
wp_update_post($post_update);
}
Based on: ACF | acf/save_post