show label text of select option rather than its value in cmb2

Question

I am trying to display the label text of my CMB2 select not the value on the frontend. Currently my select field displays a list of a specific custom post type called fleet. When I add $gas = get_post_meta( get_the_ID(), ‘gas__assign’, true ); echo $gas; into the front of my website it is displaying the value which in this case is the post ID. Is there away I can display the selected option instead of the value?

Custom Select

 $gas->add_field( array(
        'name'          => 'Assign',
        'desc'          => 'assign a vehicle',
        'id'            => $prefix . 'gas__assign',
        'type'          => 'select',
        'options'       => get_gas_options('fleettype'),
    ));

Select Field Selection of a CPT

function get_gas_options($a) {
$args = array(
    'post_type'         => 'fleet',
    'orderby'           => 'ID',
    'post_status'       => 'publish',
    'order'             => 'ASC',
    'posts_per_page'    => -1 // this will retrive all the post that is published 
);
$result = new WP_Query( $args );
$title_list[''] = "Assign a Vehicle";

if ( $result-> have_posts() ) :
while ( $result->have_posts() ) : $result->the_post();
    $title_list[get_the_ID()] = get_the_title();   
endwhile;
endif; 
wp_reset_postdata();
    
return $title_list;
}

               
         
0
, bigant841 3 years 2020-08-27T10:10:45-05:00 0 Answers 43 views 0

Leave an answer

Browse
Browse