Support Forum
Support › Meta Box Conditional Logic › Conditional logic may not be workingResolved
I've copied the below from get PHP code I've updated it to the latest release.
If I select one checkbox_list it shows but if I select both it doesn't.
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
function your_prefix_function_name( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => __( 'services section', 'your-text-domain' ),
'id' => 'services-section',
'post_types' => ['page', 'service-areas', 'service'],
'fields' => [
[
'name' => __( 'Service hero', 'your-text-domain' ),
'id' => $prefix . 'service_hero',
'type' => 'group',
'fields' => [
[
'name' => __( 'title', 'your-text-domain' ),
'id' => $prefix . 'title',
'type' => 'text',
],
[
'name' => __( 'text', 'your-text-domain' ),
'id' => $prefix . 'text',
'type' => 'text',
],
[
'name' => __( 'image', 'your-text-domain' ),
'id' => $prefix . 'image',
'type' => 'single_image',
],
[
'name' => __( 'additional_services_groups', 'your-text-domain' ),
'id' => $prefix . 'additional_services_groups',
'type' => 'checkbox_list',
'options' => [
'none' => __( 'none', 'your-text-domain' ),
'services_offered_card' => __( 'services_offered_card', 'your-text-domain' ),
'service_offered_group_of_images1' => __( 'service_offered_group_of_images1', 'your-text-domain' ),
],
],
],
],
[
'name' => __( 'services offered card', 'your-text-domain' ),
'id' => $prefix . 'services_offered_card',
'type' => 'group',
'collapsible' => true,
'clone' => true,
'sort_clone' => true,
'fields' => [
[
'name' => __( 'title', 'your-text-domain' ),
'id' => $prefix . 'title',
'type' => 'text',
],
[
'name' => __( 'text', 'your-text-domain' ),
'id' => $prefix . 'text',
'type' => 'text',
],
[
'name' => __( 'image', 'your-text-domain' ),
'id' => $prefix . 'image',
'type' => 'single_image',
],
],
'hidden' => [
'when' => [['additional_services_groups', '!=', 'services_offered_card']],
'relation' => 'or',
],
],
[
'name' => __( 'service_offered_group_of_images1', 'your-text-domain' ),
'id' => $prefix . 'service_offered_group_of_images1',
'type' => 'group',
'clone' => true,
'sort_clone' => true,
'fields' => [
[
'name' => __( 'images', 'your-text-domain' ),
'id' => $prefix . 'images',
'type' => 'single_image',
'clone' => true,
'sort_clone' => true,
],
],
'hidden' => [
'when' => [
[
'additional_services_groups',
'!=',
'service_offered_group_of_images1',
],
],
'relation' => 'or',
],
],
],
];
return $meta_boxes;
}
Hello,
If you use the field checkbox_list, please use the operator in
to check the conditional logic. Please read more on the documentation https://docs.metabox.io/extensions/meta-box-conditional-logic/#syntax
If you use the builder, please see this screenshot https://monosnap.com/file/5jHctYShpEhn4AKMaFJ3cFZu87AWRd
Hello Peter
I was able to make it work using your suggestion.
I'm happy for this ticket to show as being resolved.
Kind regards
Stephen