Not sure what I'm running into with MB Groups and some custom fields
- This topic has 3 replies, 2 voices, and was last updated 5 days, 12 hours ago by
Sean V.
-
AuthorPosts
-
January 22, 2026 at 1:10 PM #49653
Sean V
Participanti can remove the fields from the group, and they work. I can see the fields encoded in post meta in the DB. Spent too much time on it so I'm ditching the groups, but still wondering why...
Code for the Custom fields
<?php add_filter( 'rwmb_meta_boxes', 'gm_meal_plan_recipes' ); function gm_meal_plan_recipes( $meta_boxes ) { $prefix = ''; $meta_boxes[] = [ 'post_types' => ['gb-meal-plan'], 'style' => 'seamless', 'title' => __( 'GBMP Recipe Picker', 'bootscore' ), 'id' => 'gbmp-recipe-picker', 'validation' => [ 'rules' => [ $prefix . 'single_mon_image' => [ 'required' => true, ], ], ], 'tabs' => [ 'tab_mon' => 'Monday', 'tab_tue' => 'Tuesday', 'tab_wed' => 'Wednesday', 'tab_thur' => 'Thursday', 'tab_fri' => 'Friday', 'tab_sat' => 'Saturday', 'tab_collection' => 'Collection', ], 'fields' => [ [ 'type' => 'post', 'id' => $prefix . 'gbr_mon_recipe', 'name' => __( 'Monday', 'bootscore' ), 'post_type' => ['gb-recipe'], 'tab' => 'tab_mon', ], [ 'type' => 'wysiwyg', 'id' => $prefix . 'gbr_mon_summary', 'name' => __( 'Recipe Summary', 'bootscore' ), 'columns' => 6, 'tab' => 'tab_mon', ], [ 'type' => 'group', 'id' => $prefix . 'gbr_mon_group', 'name' => __( 'gbr_mon_group', 'bootscore' ), 'columns' => 6, 'fields' => [ [ 'type' => 'select', 'id' => $prefix . 'img_mon_type', 'name' => __( 'Image Type', 'bootscore' ), 'options' => [ 'single-image' => __( 'Single Image', 'bootscore' ), 'simple-gallery' => __( 'Simple Gallery', 'bootscore' ), 'custom-gallery' => __( 'Custom Gallery', 'bootscore' ), ], 'std' => __( 'single-image: Single Image', 'bootscore' ), ], [ 'type' => 'single_image', 'id' => $prefix . 'single_mon_image', 'name' => __( 'Single Image', 'bootscore' ), 'image_size' => 'medium_large', ], ], 'tab' => 'tab_mon', ], [ 'type' => 'post', 'id' => $prefix . 'gbr_tue_recipe', 'name' => __( 'Tuesday', 'bootscore' ), 'post_type' => ['gb-recipe'], 'tab' => 'tab_tue', ], [ 'type' => 'wysiwyg', 'id' => $prefix . 'gbr_tue_summary', 'name' => __( 'Recipe Summary', 'bootscore' ), 'columns' => 6, 'tab' => 'tab_tue', ], [ 'type' => 'group', 'id' => $prefix . 'gbr_tue_group', 'columns' => 6, 'fields' => [ [ 'type' => 'select', 'id' => $prefix . 'img_tue_type', 'name' => __( 'Image Type', 'bootscore' ), 'options' => [ 'single-image' => __( 'Single Image', 'bootscore' ), 'simple-gallery' => __( 'Simple Gallery', 'bootscore' ), 'custom-gallery' => __( 'Custom Gallery', 'bootscore' ), ], 'std' => __( 'single-image: Single Image', 'bootscore' ), ], [ 'type' => 'single_image', 'id' => $prefix . 'single_tue_image', 'name' => __( 'Single Image', 'bootscore' ), 'visible' => ['image_type_2', 'Single Image'], ], ], 'tab' => 'tab_tue', ], [ 'type' => 'post', 'id' => $prefix . 'gbr_wed_recipe', 'name' => __( 'Wednesday', 'bootscore' ), 'post_type' => ['gb-recipe'], 'tab' => 'tab_wed', ], [ 'type' => 'wysiwyg', 'id' => $prefix . 'gbr_wed_summary', 'name' => __( 'Recipe Summary', 'bootscore' ), 'columns' => 6, 'tab' => 'tab_wed', ], [ 'type' => 'group', 'id' => $prefix . 'gbr_wed_group', 'columns' => 6, 'fields' => [ [ 'type' => 'select', 'id' => $prefix . 'img_wed_type', 'name' => __( 'Image Type', 'bootscore' ), 'options' => [ 'single-image' => __( 'Single Image', 'bootscore' ), 'simple-gallery' => __( 'Simple Gallery', 'bootscore' ), 'custom-gallery' => __( 'Custom Gallery', 'bootscore' ), ], 'std' => __( 'single-image: Single Image', 'bootscore' ), ], [ 'type' => 'single_image', 'id' => $prefix . 'single_wed_image', 'name' => __( 'Single Image', 'bootscore' ), 'visible' => ['image_type_2', 'Single Image'], ], ], 'tab' => 'tab_wed', ], [ 'type' => 'post', 'id' => $prefix . 'gbr_thu_recipe', 'name' => __( 'Thursday', 'bootscore' ), 'post_type' => ['gb-recipe'], 'tab' => 'tab_thur', ], [ 'type' => 'wysiwyg', 'id' => $prefix . 'gbr_thu_summary', 'name' => __( 'Recipe Summary', 'bootscore' ), 'columns' => 6, 'tab' => 'tab_thur', ], [ 'type' => 'group', 'id' => $prefix . 'gbr_thu_group', 'columns' => 6, 'fields' => [ [ 'type' => 'select', 'id' => $prefix . 'img_thu_type', 'name' => __( 'Image Type', 'bootscore' ), 'options' => [ 'single-image' => __( 'Single Image', 'bootscore' ), 'simple-gallery' => __( 'Simple Gallery', 'bootscore' ), 'custom-gallery' => __( 'Custom Gallery', 'bootscore' ), ], 'std' => __( 'single-image: Single Image', 'bootscore' ), ], [ 'type' => 'single_image', 'id' => $prefix . 'single_thur_image', 'name' => __( 'Single Image', 'bootscore' ), 'visible' => ['image_type_4', 'Single Image'], ], ], 'tab' => 'tab_thur', ], [ 'type' => 'post', 'id' => $prefix . 'gbr_fri_recipe', 'name' => __( 'Friday', 'bootscore' ), 'post_type' => ['gb-recipe'], 'tab' => 'tab_fri', ], [ 'type' => 'wysiwyg', 'id' => $prefix . 'gbr_fri_summary', 'name' => __( 'Recipe Summary', 'bootscore' ), 'columns' => 6, 'tab' => 'tab_fri', ], [ 'type' => 'group', 'id' => $prefix . 'gbr_fri_group', 'columns' => 6, 'fields' => [ [ 'type' => 'select', 'id' => $prefix . 'img_fri_type', 'name' => __( 'Image Type', 'bootscore' ), 'options' => [ 'single-image' => __( 'Single Image', 'bootscore' ), 'simple-gallery' => __( 'Simple Gallery', 'bootscore' ), 'custom-gallery' => __( 'Custom Gallery', 'bootscore' ), ], 'std' => __( 'single-image: Single Image', 'bootscore' ), ], [ 'type' => 'single_image', 'id' => $prefix . 'single_fri_image', 'name' => __( 'Single Image', 'bootscore' ), 'visible' => ['image_type_4', 'Single Image'], ], ], 'tab' => 'tab_fri', ], [ 'type' => 'post', 'id' => $prefix . 'gbr_sat_recipe', 'name' => __( 'Saturday', 'bootscore' ), 'post_type' => ['gb-recipe'], 'tab' => 'tab_sat', ], [ 'type' => 'wysiwyg', 'id' => $prefix . 'gbr_sat_summary', 'name' => __( 'Recipe Summary', 'bootscore' ), 'columns' => 6, 'tab' => 'tab_sat', ], [ 'type' => 'group', 'id' => $prefix . 'gbr_sat_group', 'columns' => 6, 'fields' => [ [ 'type' => 'select', 'id' => $prefix . 'img_sat_type', 'name' => __( 'Image Type', 'bootscore' ), 'options' => [ 'single-image' => __( 'Single Image', 'bootscore' ), 'simple-gallery' => __( 'Simple Gallery', 'bootscore' ), 'custom-gallery' => __( 'Custom Gallery', 'bootscore' ), ], 'std' => __( 'single-image: Single Image', 'bootscore' ), ], [ 'type' => 'single_image', 'id' => $prefix . 'single_sat_image', 'name' => __( 'Single Image', 'bootscore' ), 'visible' => ['image_type_4', 'Single Image'], ], ], 'tab' => 'tab_sat', ], [ 'type' => 'post', 'id' => $prefix . 'gb_collection_id', 'name' => __( 'Collection', 'bootscore' ), 'post_type' => ['wprm_collection'], 'tab' => 'tab_collection', ], ], ]; return $meta_boxes; }autogenerated code to display fields in the group
<?php $group = rwmb_meta( 'gbr_mon_group', [ 'object_type' => '' ] ); // Field img_mon_type: echo $group[ 'img_mon_type' ] ?? ''; // Field single_mon_image: $image_id = $group[ 'single_mon_image' ] ?? 0; $image = RWMB_Image_Field::file_info( $image_id, [ 'size' => 'thumbnail' ] ); ?> <h3>Logo</h3> <img src="<?php echo $image['url']; ?>"> <?php ?>Paste bin with template file
https://pastebin.com/VXU5gGZCQuery Monitor Logs
Debug Array ( [collapsible] => [save_state] => [group_title] => Entry [default_state] => expanded [id] => gbr_mon_group [name] => gbr_mon_group [type] => group [label_description] => [multiple] => [std] => [desc] => [format] => [before] => <div class="rwmb-column rwmb-column-6 "> [after] => </div><!-- .rwmb-column --></div><!-- .rwmb-row --> [field_name] => gbr_mon_group [placeholder] => [save_field] => 1 [clone] => [min_clone] => 0 [max_clone] => 0 [sort_clone] => [add_button] => + Add more [clone_default] => [clone_as_multiple] => [clone_empty_start] => [class] => rwmb-group-non-cloneable [disabled] => [required] => [autofocus] => [attributes] => Array ( ) [sanitize_callback] => [fields] => Array ( [0] => Array ( [select_all_none] => [flatten] => 1 [options] => Array ( [single-image] => Single Image [simple-gallery] => Simple Gallery [custom-gallery] => Custom Gallery ) [id] => img_mon_type [name] => Image Type [type] => select [label_description] => [multiple] => [std] => single-image: Single Image [desc] => [format] => [before] => <div class="rwmb-row"><div class="rwmb-column rwmb-column-12 "> [after] => </div><!-- .rwmb-column --></div><!-- .rwmb-row --> [field_name] => img_mon_type [placeholder] => [save_field] => 1 [clone] => [min_clone] => 0 [max_clone] => 0 [sort_clone] => [add_button] => + Add more [clone_default] => [clone_as_multiple] => [clone_empty_start] => [class] => [disabled] => [required] => [autofocus] => [attributes] => Array ( ) [sanitize_callback] => [storage] => [column] => column-6971bd322a178 ) [1] => Array ( [std] => [mime_type] => image [max_file_uploads] => 1 [force_delete] => [max_status] => [js_options] => Array ( [imageSize] => medium_large [mimeType] => image [maxFiles] => 1 [forceDelete] => [maxStatus] => [addTo] => end ) [add_to] => end [upload_dir] => [unique_filename_callback] => [id] => single_mon_image [name] => Single Image [type] => single_image [label_description] => [multiple] => [desc] => [format] => [before] => <div class="rwmb-row"><div class="rwmb-column rwmb-column-12 "> [after] => </div><!-- .rwmb-column --></div><!-- .rwmb-row --> [field_name] => single_mon_image [placeholder] => [save_field] => 1 [clone] => [min_clone] => 0 [max_clone] => 0 [sort_clone] => [add_button] => + Add more [clone_default] => [clone_as_multiple] => [clone_empty_start] => [class] => [disabled] => [required] => [autofocus] => [attributes] => Array ( [class] => rwmb-image_advanced [data-single-image] => 1 ) [sanitize_callback] => [image_size] => medium_large [input_name] => _file_single_mon_image [index_name] => _index_single_mon_image [storage] => [column] => column-6971bd322a17a ) ) [tab] => tab_mon [storage] => RWMB_Post_Storage Object ( [object_type:protected] => post ) [column] => column-6971bd322a177 ) wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Group ID: mon| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type ID: mon| img_mon_type wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type: mon| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image ID: mon| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Render: mon| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Group ID: tue| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type ID: tue| img_tue_type wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type: tue| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image ID: tue| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Render: tue| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Group ID: wed| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type ID: wed| img_wed_type wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type: wed| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image ID: wed| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Render: wed| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Group ID: thu| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type ID: thu| img_thu_type wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type: thu| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image ID: thu| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Render: thu| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Group ID: fri| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type ID: fri| img_fri_type wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type: fri| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image ID: fri| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Render: fri| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Group ID: sat| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type ID: sat| img_sat_type wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Type: sat| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image ID: sat| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Image Render: sat| wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Debug Array ( [mon] => Array ( [full_day] => Monday [post_id] => 145994 [recipe_id] => 151185 [summary] => <p>Monday Summary</p> [img_id] => 0 ) [tue] => Array ( [full_day] => Tuesday [post_id] => 145608 [recipe_id] => 150912 [summary] => <p>Tue Summary</p> [img_id] => 0 ) [wed] => Array ( [full_day] => Wednesday [post_id] => 146036 [recipe_id] => 151227 [summary] => <p>Wed Summary</p> [img_id] => 0 ) [thu] => Array ( [full_day] => Thursday [post_id] => 145959 [recipe_id] => 151158 [summary] => <p>Thur Summary</p> [img_id] => 0 ) [fri] => Array ( [full_day] => Friday [post_id] => 144961 [recipe_id] => 150308 [summary] => <p>Fri Summary</p> [img_id] => 0 ) [sat] => Array ( [full_day] => Saturday [post_id] => 145677 [recipe_id] => 150968 [summary] => <p>Sat Summary</p> [img_id] => 0 ) ) wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Error No image ID found in $data wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Error No image ID found in $data wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Error No image ID found in $data wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Error No image ID found in $data wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Error No image ID found in $data wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitor Error No image ID found in $data wp-content/plugins/query-monitor/collectors/logger.php Plugin: query-monitorJanuary 23, 2026 at 10:30 PM #49665Peter
ModeratorHello Sean,
Thanks for reaching out.
I'm checking the issue and I will get back to you as soon as I have more information.
January 24, 2026 at 2:36 PM #49667Peter
ModeratorHello Sean,
I check the code that you created to output field value in the frontend, and there are some basic issues:
1.
$group_id = "gbr_' . $abbr . '_group";wrong single quotes to get the group field ID. It should be
$group_id = "gbr_" . $abbr . "_group";2.
$img_type = $group[ $field_name ] ?? ''; $image_id = $group[ 'single_mon_image' ] ?? 0;you get the group value with this code
$group_value = rwmb_meta( $group_id, [ 'object_type' => '' ] );but get the subfield value from
$groupvariable. It should be$img_type = $group_value[ $field_name ] ?? ''; $image_id = $group_value[ 'single_mon_image' ] ?? 0;I hope that makes sense.
January 24, 2026 at 2:43 PM #49668Sean V
ParticipantYes, it makes sense. Targeting the group first had crossed my mind, but I wasn't connecting what
$group_value = rwmb_meta( $group_id, [ 'object_type' => '' ] );was doing... I had it there, I obviously had the variables named incorrectly. I just didn't put two and two together.I'll keep it in mind for next time.
I can see how group can be useful, and I do know you can set a group to store variables however you want. That said, it would be nice if there was a layout option that behaved like a div that only dealt with layout in the editor and you didn't need to think about dimension when calling the custom fields.
Thank you for taking the time to figure out what I did wrong.
-
AuthorPosts
- You must be logged in to reply to this topic.