Hello Yasmine,
You can define an array of custom fields that is not changed across field groups (reusable), then use the function array_merge()
to add more fields to the reusable field group to other field groups for your requirements. For example:
add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
function your_prefix_function_name( $meta_boxes ) {
// Reusing field group 1
$field_group_1 = [
[
'name' => __( 'Datetime', 'your-text-domain' ),
'id' => 'datetime_jeq28wycry',
'type' => 'datetime',
]
];
$additional_fields = [
[
'name' => __( 'Custom Html', 'your-text-domain' ),
'type' => 'custom_html',
],
];
$field_group_2 = array_merge( $field_group_1, $additional_fields );
$meta_boxes[] = [
'title' => __( 'Field Group 1', 'your-text-domain' ),
'id' => 'field-group-1',
'post_types' => 'page',
'fields' => $field_group_1,
];
$meta_boxes[] = [
'title' => __( 'Field Group 2', 'your-text-domain' ),
'id' => 'field-group-2',
'post_types' => 'page',
'fields' => $field_group_2,
];
return $meta_boxes;
}