我有一个 cmb2 选择字段,我在其中使用函数加载类别,以及一个用于上传类别图像的字段。它们共同构成了一个中继器组字段。现在,每次从管理员端设置类别时,我都需要检查它们是否都是唯一的。也就是说,不应多次输入任何类别(管理员不小心)。
function bootstrap()
{
add_action( 'cmb2_admin_init', __NAMESPACE__ . '\\fields' );
}
function fields()
{
$meta = new_cmb2_box(
array(
'id' => 'settings',
'title' => __( 'Settings' ),
'object_types' => array( 'options-page' ),
'option_key' => 'shop_settings',
'desc' => __( 'Fields for storing settings' ),
)
);
$group_field_id = $meta -> add_field([
'id' => 'my_group_field',
'type' => 'group',
'options' => array(
'add_button' => __( 'Add Field', 'cmb2' ),
'remove_button' => __( 'Remove Field', 'cmb2' ),
'sortable' => true,
),
]);
$meta -> add_group_field($group_field_id, [ //this is the field that requires the check
'id' => 'selection_list',
'name' => __( 'Category Name'),
'type' => 'select',
'options' => my__get_categories(), //loads all the category names
]);
$meta -> add_group_field($group_field_id, [
'id' => 'cat_image',
'name' => 'Category Image',
'type' => 'file',
'text' => array(
'add_upload_file_text' => 'Add or Upload Image'
),
'query_args' => array(
'type' => 'image/*',
),
'preview_size' => 'large',
]);
}
但是我如何制作一个功能来实现相同的功能。任何帮助深表感谢。提前致谢