Support Forum
Support › Meta Box Conditional Logic › Conditional Logic - Advanced Taxonomy with 2 rules
Hi there -
I have a set of custom fields that should show under two conditions:
1. A taxonomy called "Community" is set to "Roundtable"
2. A taxonomy called "Training" is set to "Seminars/Webinars"
These rules look like this: https://www.awesomescreenshot.com/image/41751059?key=8c1cd6d15b0f522d348708db4a1c2442
Note: these taxonomies (Community and Training) begin in a separate custom fields set and are chosen via Advanced Select custom field set to taxonomy.
They look like this: https://www.awesomescreenshot.com/image/41750915?key=fdf0226242b30974020e26846cc609fb
For the rules, I can only get this to work for one or the other, but not both.
It will work for the first rule if I have it set to "Any"
It will work for the second rule if I have it set to "All"
I've also tried changing the parameters using "in" "=" and "contains"
I've also tried using Toggle rules but couldn't get that to work at all.
Here's the generated PHP code:
<div>
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
function your_prefix_function_name( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => __( 'Seminars/Webinars & Roundtables', 'your-text-domain' ),
'id' => 'seminars-webinars-roundtables',
'post_types' => ['member-content'],
'visible' => [
'when' => [['training_category', 'in', 75], ['community_category', 'in', 78]],
'relation' => 'or',
],
'fields' => [
[
'name' => __( 'Vimeo URL', 'your-text-domain' ),
'id' => $prefix . 'sem-web-url',
'type' => 'url',
],
[
'name' => __( 'Description', 'your-text-domain' ),
'id' => $prefix . 'sem-web-description',
'type' => 'wysiwyg',
],
[
'name' => __( 'Transcript', 'your-text-domain' ),
'id' => $prefix . 'sem-web-transcript',
'type' => 'wysiwyg',
],
[
'name' => __( 'Chat', 'your-text-domain' ),
'id' => $prefix . 'sem-web-chat',
'type' => 'wysiwyg',
],
[
'type' => 'heading',
'name' => __( 'Roundtable Guest', 'your-text-domain' ),
'visible' => [
'when' => [['community_category', 'in', 78]],
'relation' => 'or',
],
],
[
'name' => __( 'Roundtable Guest Name', 'your-text-domain' ),
'id' => $prefix . 'roundtable_guest_name',
'type' => 'text',
'visible' => [
'when' => [['community_category', 'in', 78]],
'relation' => 'or',
],
],
[
'name' => __( 'Roundtable Guest Title', 'your-text-domain' ),
'id' => $prefix . 'roundtable_guest_title',
'type' => 'text',
'visible' => [
'when' => [['community_category', 'in', 78]],
'relation' => 'or',
],
],
[
'name' => __( 'Roundtable Guest Company', 'your-text-domain' ),
'id' => $prefix . 'roundtable_guest_company',
'type' => 'text',
'visible' => [
'when' => [['community_category', 'in', 78]],
'relation' => 'or',
],
],
[
'name' => __( 'Roundtable Guest Headshot', 'your-text-domain' ),
'id' => $prefix . 'roundtable_guest_headshot',
'type' => 'single_image',
'visible' => [
'when' => [['community_category', 'in', 78]],
'relation' => 'or',
],
],
],
];
return $meta_boxes;
}
</div>
Hello,
I've tested this case on my demo site but do not see any issues. Please try to deactivate all plugins except Meta Box, MB extension plugins, switch to a standard theme and remove all other field groups then check this again.
Okay - I just recreated and tested step by step.
I believe the problem is this: The taxonomies (Training and Community) also use conditional logic. They only show when a button is previously selected.
Without this conditional logic, the 2 rules to show the custom fields group work.
When the conditional logic (with the buttons to show the taxonomies), it does not work.
Is it possible to fix this?
This site will have a pretty big library of resources and the conditional logic makes the data entry for my client much easier to keep it organized.
I used the same field group ("Seminars/Webinars & Roundtables") as I originally posted.
Here is the test group I created with the buttons and taxonomies:
<div>
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
function your_prefix_function_name( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => __( 'Tax test', 'your-text-domain' ),
'id' => 'tax-test',
'post_types' => ['member-content'],
'fields' => [
[
'name' => __( 'Which bucket does this go into?', 'your-text-domain' ),
'id' => $prefix . 'category_type',
'type' => 'button_group',
'options' => [
'Resource' => __( 'Resource', 'your-text-domain' ),
'Training' => __( 'Training', 'your-text-domain' ),
'Community' => __( 'Community', 'your-text-domain' ),
],
'required' => true,
],
[
'name' => __( 'Community', 'your-text-domain' ),
'id' => $prefix . 'comm_tax',
'type' => 'taxonomy',
'taxonomy' => ['community'],
'field_type' => 'select_advanced',
'visible' => [
'when' => [['category_type', '=', 'Community']],
'relation' => 'or',
],
],
[
'name' => __( 'Resource', 'your-text-domain' ),
'id' => $prefix . 'resource_tax',
'type' => 'taxonomy',
'taxonomy' => ['resource'],
'field_type' => 'select_advanced',
'visible' => [
'when' => [['category_type', '=', 'Resource']],
'relation' => 'and',
],
],
[
'name' => __( 'Training', 'your-text-domain' ),
'id' => $prefix . 'training_tax',
'type' => 'taxonomy',
'taxonomy' => ['training'],
'field_type' => 'select_advanced',
'visible' => [
'when' => [['category_type', '=', 'Training']],
'relation' => 'or',
],
],
],
];
return $meta_boxes;
}
</div>
Hello,
If a field training_category
or community_category
is shown/hidden by another conditional logic then the second logic does not work. This issue has been escalated to the development team and they are still working on it. Hopefully, it will be fixed soon.
Thank you - looking forward to the fix 🙂
Any news on this? 🙂
Not yet. The development team is still working on this issue. I will let you know when I have any information.