Set the title of a custom post automatically by using info from custom fields?

The issue with your code is that the get_metadata() function returns an array of values, not a single value. So when you concatenate $first and $last variables in this line $title = $first . ‘ ‘ . $last;, you are actually concatenating two arrays, which results in the “Array Array” title.

To fix this, you can use the get_post_meta() function instead of get_metadata() to retrieve the first and last name values as follows:

$first = get_post_meta( $post_id, 'first_name', true ); //meta for first name
$last = get_post_meta( $post_id, 'last_name', true );   //meta for last name

The third parameter true in the get_post_meta() function specifies that you want to retrieve a single value instead of an array of values.

Here’s the updated code:

add_filter( 'save_post_practitioners', 'hexagon_practitioner_set_title', 
10, 3 );
function hexagon_practitioner_set_title ( $post_id, $post, $update ){
//This temporarily removes filter to prevent infinite loops
remove_filter( 'save_post_practitioners', __FUNCTION__ );

//get first and last name meta
$first = get_post_meta( $post_id, 'first_name', true ); //meta for first 
name
$last = get_post_meta( $post_id, 'last_name', true );   //meta for last 
name

$title = $first . ' ' . $last;

//update title
wp_update_post( array( 'ID'=>$post_id, 'post_title'=>$title ) );

//redo filter
add_filter( 'save_post_practitioners', __FUNCTION__, 10, 3 );
}

This should set the post title to “First Name Last Name” as you intended.