One of the Carbon Fields developers here.
Thank you for your feedback!
Currently, the Carbon Fields stores only the keys and they don’t have a built-in method to retrieve the selected values from the options array.
You can pass a callable which returns an array with the options as an argument to the add_options
method.
function available_options() {
return array(
'windows' => 'Windows',
'mac' => 'Mac OS/ OSX',
'linux' => 'Linux',
'android' => 'Android',
'mobile' => 'Mobile',
'tv' => 'Smart TV',
'desktop' => 'Desktop',
'router' => 'Router',
'raspberrypi' => 'Raspberry Pi',
);
}
Field::make( 'multiselect', 'available_on', 'Available on' )
->add_options( 'available_options' ),
Then use the function when you want to retrieve the correct values from the stored keys:
$all_options = available_options();
$available_on = carbon_get_post_meta( $post_id, 'available_on' );
foreach ( $available_on as $option_key ) {
echo $all_options[ $option_key ];
}