Display ACF data as post title on 'publish' of Wordpress post?

Here is my code:



function my_post_title_updater( $post_id ) {

$my_post = array();
$my_post['ID'] = $post_id;

$brand = get_field('brand');
$asset = get_field('asset');
$language = get_field('language');

$countryfield = get_field_object('country');
$countryvalue = get_field('country');
$country = $countryfield['choices'][ $countryvalue ];

if ( get_post_type() == 'project' ) {
$my_post['post_title'] = $brand . ' ' . $asset . ' ' . $country . ' ' . $language ;
}

wp_update_post( $my_post );

}

add_action('acf/save_post', 'my_post_title_updater', 20);


On publishing a Wordpress post this function is supposed to create a title based on a few Advanced Custom Fields. At the moment what it does is gets 'brand', 'asset' and 'language', but not 'country'. However, upon clicking 'update' of the post it will then display the country in the title.



Any help would be much appreciated.



Answers

Try:



$country = $countryfield['choices'] . $countryvalue;