Support Forum
Support › Meta Box Group › Select Advanced is not empty when cloned.
I have a "Group" that has a field type of "Post" that I amusing "Select Advanced". When I DO NOT have "Multiple" enabled everything works as expected. When I clone the group the field is empty.
When I have "Multiple" enabled and I clone the group the field has the last value that I had entered.
I believe this problem was discussed in 2016 "https://support.metabox.io/topic/select-advance-clone-issue/?swcfpc=1" and again in "https://support.metabox.io/topic/select-advance-clone-issue-2/?swcfpc=1".
I don't understand why the bug still exists in 2023, it should have been rolled out with any one of the many updates.
Here is the code:
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
function your_prefix_function_name( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => __( 'Event', 'your-text-domain' ),
'id' => 'event',
'post_types' => ['event'],
'fields' => [
[
'name' => __( 'Description', 'your-text-domain' ),
'id' => $prefix . 'description',
'type' => 'wysiwyg',
],
[
'name' => __( 'Location', 'your-text-domain' ),
'id' => $prefix . 'location',
'type' => 'post',
'post_type' => ['location'],
],
[
'name' => __( 'Schedule', 'your-text-domain' ),
'id' => $prefix . 'schedule',
'type' => 'group',
'collapsible' => true,
'default_state' => 'collapsed',
'group_title' => '{schedule_item}',
'clone' => true,
'sort_clone' => true,
'fields' => [
[
'name' => __( 'Schedule Item', 'your-text-domain' ),
'id' => $prefix . 'schedule_item',
'type' => 'text',
'required' => true,
],
[
'name' => __( 'Host', 'your-text-domain' ),
'id' => $prefix . 'host',
'type' => 'post',
'post_type' => ['speaker'],
'field_type' => 'select_advanced',
'multiple' => true,
'placeholder' => __( 'Select Host', 'your-text-domain' ),
],
[
'name' => __( 'Date', 'your-text-domain' ),
'id' => $prefix . 'date',
'type' => 'date',
],
[
'name' => __( 'All Day', 'your-text-domain' ),
'id' => $prefix . 'all_day',
'type' => 'switch',
'style' => 'rounded',
'on_label' => 'Yes',
'off_label' => 'No',
'std' => true,
'columns' => 3,
],
[
'name' => __( 'Start Time', 'your-text-domain' ),
'id' => $prefix . 'start_time',
'type' => 'time',
'columns' => 4,
'hidden' => [
'when' => [['all_day', '=', true]],
'relation' => 'and',
],
],
[
'name' => __( 'End Time', 'your-text-domain' ),
'id' => $prefix . 'end_time',
'type' => 'time',
'std' => '{start_time}',
'columns' => 4,
'hidden' => [
'when' => [['all_day', '=', true]],
'relation' => 'or',
],
],
],
],
],
];
return $meta_boxes;
}
Additionally I am also having a problem with the "Switch" field. I have it set to be on by default but when it is cloned it is off.
Hello,
Thanks for your feedback.
I see the issue with the post
field, I've escalated this issue to the development team to fix it in future updates.
Regarding the switch
field, if you want to clone default value, please enable clone_default
for the group field. Following the documentation https://docs.metabox.io/extensions/meta-box-group/#clone-default-values
I can confirm I am seeing the same problem. Hope it gets fixed soon.