Hi @xavierserranoa
We do have a cmb2_get_field( 'cmb_id', 'field_id' )->options()
where you would want to pass in your ID parameter for the metabox, and then the ID parameter for the field that you’re wanting to fetch. HOWEVER this will only work if your using the cmb2_init hook to register, which may not be the case. If you’re using the cmb2_admin_init hook to register your stuff, then the function won’t find its data.
Since we recommending using the cmb2_admin_init
hook unless this is specifically for the frontend, we have the following as a better alternative.
First define callback to provide the available options.
function yourprefix_demo_select_options() {
return array(
'' => __( 'Nope', 'cmb2' ),
'standard' => __( 'Option One', 'cmb2' ),
'custom' => __( 'Option Two', 'cmb2' ),
'none' => __( 'Option Three', 'cmb2' ),
);
}
Then utilize that function when constructing the metabox.
$cmb_demo->add_field( array(
'name' => __( 'Test Select', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => '_yourprefix_demo_select',
'type' => 'select',
'options_cb' => 'yourprefix_demo_select_options',
) );
This way you could use the same function elsewhere to get its data, but also pass them in to the dropdown.