Support Forum
Support › Meta Box Group › Cannot manage to work with a Select field in group
How it will be the code?
I use this:
array(
'name' => esc_html__( 'Depends of', 'pbc' ),
'id' => "{$prefix}depends",
'type' => 'group',
'clone' => true,
'sort_clone' => true,
'fields' => array(
// SELECT BOX VARIATIONS
array(
'name' => __( 'Variation', 'pbc' ),
'id' => "{$prefix}depvar",
'type' => 'select',
'options' => $var_options,
'multiple' => false,
'std' => '',
'placeholder' => __( 'Select a Variation', 'pbc' ),
),
),
), //array
Did you set value for $var_options
? Here is my test:
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
$prefix = 'mbox_';
$var_options = array(
'a' => 'First option',
'b' => 'Second option',
);
$meta_boxes[] = array(
'title' => esc_html__( 'Standard Fields', 'your-prefix' ),
'fields' => array(
array(
'name' => esc_html__( 'Depends of', 'pbc' ),
'id' => "{$prefix}depends",
'type' => 'group',
'clone' => true,
'sort_clone' => true,
'fields' => array(
// SELECT BOX VARIATIONS
array(
'name' => __( 'Variation', 'pbc' ),
'id' => "{$prefix}depvar",
'type' => 'select',
'options' => $var_options,
'multiple' => false,
'std' => '',
'placeholder' => __( 'Select a Variation', 'pbc' ),
),
),
), //array
),
);
return $meta_boxes;
}
And here is the result:
Hello!, yes it loads all entries from a post type:
//Variations Options
$var_options = array();
$variationscpt = get_posts(array(
'post_type' => 'variation',
'posts_per_page' => -1,
'orderby' => 'name',
'order' => 'ASC'
));
$variationscpt_item = array();
foreach ($variationscpt as $var_item) {
$var_options[$var_item->ID] = $var_item->post_title;
}
Hello, I've found the error. I was using meta-box as composer, and it was not working...
Now as plugin it works correctly.