When you open the select post window the previous selected posts aren't selected
If i have let say 2 Posts previously selected and saved they aren't selected in the popup when i click to search again. The same aplies when I select a post and then search (inside the popup) for another post it de-selects the first post
Can you provide your CMB2 code configuration so that we can attempt to recreate the setup locally and test?
array(
'name' => __('Featured Recipes'),
'id' => '_featured_recipes_list',
'type' => 'post_search_text', // This field type
'post_type' => 'Recept',
'select_type' => 'select',
'select_behavior' => 'add'
)
Could you post everything as part of the new new_cmb2_box( ... ) onwards? instead of just one field? Just in case some other part is playing a part.
Well im using the cmb2 box as dynamic addable items so its not the conventional setup. here is the code
$cmb = new_cmb2_box(array(
'id' => $prefix . 'repeater',
'title' => 'Page Layout',
'object_types' => array('page', 'nieuws', 'vacature'), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
));
$group_field_id = $cmb->add_field(array(
'id' => $prefix . '_repeat_group',
'type' => 'group',
'description' => __('Generates reusable form entries', 'cmb2'),
'options' => array(
'group_title' => __('Entry {#}', 'cmb2'),
'add_button' => __('Add Another Entry', 'cmb2'),
'remove_button' => __('Remove Entry', 'cmb2'),
'sortable' => true,
),
));
$dataArrayWrapper = InitMetaBoxes($group_field_id, $isArchive);
Then I add the array (Im using cmb2-conditionals)
array(
'name' => __('Featured Recipes'),
'id' => '_featured_recipes_list',
'type' => 'post_search_text', // This field type
'post_type' => 'Recept',
'select_type' => 'select',
'select_behavior' => 'add',
'attributes' => array(
'data-conditionals-id' => id,
'data-conditionals-value' => value
)
)
$cmb->add_group_field($id, $array);
I have already fixed it for my project by writing custom code in the plugin so it saves the selected values in variables and reads that and checks the correct item on search or reload
Just for completeness sake, for myself or anyone else wanting to attempt debugging, what do you have for the InitMetaBoxes() function? assuming that's something you can share at the moment.
function InitMetaBoxes($groupFieldId, $isArchive = false)
{
$dataArrayWrapper = [];
$dataArrayWrapper[] = $mainContentDataArray = main_content_metabox_data($groupFieldId, 'mainContent');
$dataArrayWrapper[] = $subContentDataArray = sub_content_metabox_data($groupFieldId, 'subContent');
$dataArrayWrapper[] = $inlineImagesDataArray = inline_images_metabox_data($groupFieldId, 'inlineImages');
$dataArrayWrapper[] = $featuredPostDataArray = cmb2_featured_post_metabox_data($groupFieldId, 'featuredPost');
$dataArrayWrapper[] = $featuredRecipesDataArray = featured_recipes_metabox_data($groupFieldId, 'featuredRecipes');
$dataArrayWrapper[] = $customPostsDataArray = cmb2_custom_post_data($groupFieldId, 'customPost');
$dataArrayWrapper[] = $advertisementDataArray = advertisement_metabox_data($groupFieldId, 'ad');
$dataArrayWrapper[] = $sliderDataArray = text_slider_metabox_data($groupFieldId, 'textSlider');
$dataArrayWrapper[] = $headerTextbox = header_textbox_metabox_data($groupFieldId, 'headerTextbox');
$dataArrayWrapper[] = $archiveListDataArray = archive_list_metabox_init($groupFieldId, 'archiveList');
$dataArrayWrapper[] = $featuredNewsListDataArray = latest_news_metabox_data($groupFieldId, 'featuredNews');
$dataArrayWrapper[] = $featuredProductsListDataArray = products_featured_metabox_data($groupFieldId, 'featuredProducts');
$dataArrayWrapper[] = $instagramDataArray = instagram_metabox_data($groupFieldId, 'instagram');
$dataArrayWrapper[] = $titleCenteredDataArray = title_centered_metabox_data($groupFieldId, 'centeredTitle');
return $dataArrayWrapper;
}
InitMetaBoxes() adds all box data for all diffrent types of metaboxes i have created like this
function latest_news_metabox_data($groupId, $filter)
{
return array(
'data' =>
array(
array(
'name' => __('Title'),
'desc' => __(''),
'id' => '_featured_news_title',
'type' => 'text',
'default' => 'Meer interessant nieuws',
'attributes' => array(
'required' => TRUE,
),
),
array(
'name' => 'Laatste 4 nieuwsartiekelen',
'desc' => __('If checked it will show the latest 4 news items otherwise it is user defined', 'msft-newscenter'),
'id' => '_latest_news',
'type' => 'checkbox',
'attributes' => array(),
),
array(
'name' => __('Nieuws Berichten'),
'id' => '_news_items',
'type' => 'post_search_text', // This field type
// post type also as array
'post_type' => ['nieuws'],
// Default is 'checkbox', used in the modal view to select the post type
'select_type' => 'select',
// Will replace any selection with selection from modal. Default is 'add'
'select_behavior' => 'replace',
'attributes' => array(
'required' => FALSE
),
),
),
'selectFilter' => $filter
);
}