As far as I can tell (although I hope I'm wrong), it looks like meta boxes can be shown/hidden based on the value of a custom field, but not based on whether or not the post has a particular taxonomy term. Is that correct? I think I read about a way to do this with code, but I was really hoping to be able to do it from the Builder plugin. Is that possible?
The Builder lacks of supporting for taxonomies for Conditional Logic at the moment. You can do that with Custom Attributes in the Advanced tabs. The attributes can be found in docs of Conditional Logic docs here: https://docs.metabox.io/extensions/meta-box-conditional-logic/#using-with-taxonomies
Anh, I have tried this, but it only seems to work if a taxonomy has been selected and saved to the post. I have been trying to show fields based on the selection of a taxonomy_advanced field before saving the post with no luck.
taxonomy_advanced field, it works similar to any other field.
You can use
in condition and both works. Remember to use term ID to specify the value.
So, you can write the condition like this:
'visible' => ['field_id', 'contains', 4], // 4 is the term ID
'visible' => ['field_id', 'in', [4, 2]], // 4, 2 are term IDs. In this case, the field will be visible if the tax_advanced has any term with the ID specified.
Please see this video for demo:
Hopefully we see a more visual way to select taxonomy terms (like hierarchical).
I need this feature too. Any update as to if it will be coming to Builder anytime soon?
After almost a two year break, I'm trying to figure this out again. In Ahn's initial reply, he said to use "Custom Attributes" in the "Advanced" tab. I've tried to do that, but I think something is wrong. My custom taxonomy is called "Plugin Category" with a slug of "plugin-category". I'm trying to display this meta box any time the "Plugin Category" is set to "Image Optimization" (slug for that term is "image-optimization").
First, I tried this custom attribute:
hidden > ['slug:tax_input[plugin-category]', '!=', 'image-optimization']
Sadly, that hid the meta box everywhere, even if the post was part of the image-optimization plugin category.
Next, I tried these custom attributes (as mentioned here: https://docs.metabox.io/extensions/meta-box-builder/):
tax_query.0.taxonomy > plugin-category
tax_query.0.field > slug
tax_query.0.terms > image-optimization
That didn't seem to have any effect. What am I doing wrong?
I recommend using the field
taxonomy_advanced to select a taxonomy for the post and show/hide another meta box base on the field value. See my screen record https://share.getcloudapp.com/YEuQkPlk.
Thanks for the screen recording. I had tried that, but I didn't get it set up quite right. I think maybe I had used "=" instead of "in" as the comparison operator when I tried before. It's working now. Thanks for the help!
If now isn't a good time to make this functionality more user-friendly, can you re-share your CloudApp video again so I can try to figure out what's wrong with mine? I'm getting an error when I load your video reading "This item has exceeded its view limit!"
...and now it's not working again. I can set it to "Hidden" in, or "Visible" in, and either way it's showing up on every single post in my custom post type. I thought maybe it had to do with conditional logic related to taxonomies, but it looks like conditional logic in general is broken. I set it to only display if true = false, but it is still being displayed.
Can you please share some screenshots on your site? And the code that creates the fields and conditional logic.
Please deactivate all plugins except Meta Box, MB extensions and switch to the standard theme of WordPress to avoid any conflicting issues.
For me, it worked. I just entered the ID of the Custom Field => contains => (ID of the Taxonomy).
I was using a regular Taxonomy Field.
It worked like a charm