Populate select field with Fields from another CPT

To Get this to work you will need to replace the Text “Team Leader” with the name of the select field you wish to populate. Everything else is a Basic wordpress Query


add_filter( 'wpt_field_options', 'populate_select', 10, 3);
function populate_select( $options, $title, $type ){
    switch( $title ){
        case 'Team leader':
            $options = array();
			$args = array(
                'post_type'        => 'team-leader',
                'post_status'      => 'publish',
				'meta_query' => array(
        							array(
							            'key'     => 'wpcf-active',
							            'value'   => 'Yes',
							            'compare' => '=',
        								),
									),
								);
            $posts_array = get_posts( $args );
            foreach ($posts_array as $post) {
                $first_name = get_post_meta($post->ID,'wpcf-first_name');
                $last_name = get_post_meta($post->ID,'wpcf-tmsurname');
                $options[] = array(
                    '#value' => $post->ID,
                    '#title' => $first_name[0]." ".$last_name[0],
                     );
                }
               
                break;
}
    return $options;
}