Cannot Hide a Widget if a Meta Field Is Empty
I cannot hide a widget when the meta field is empty. How do I set it up?
Although this setup seems to check for the presence of content in the meta field, it does not operate correctly.
Please note that a different condition should be used to make Dynamic Visibility work properly.
As an example, we will try to hide the Dynamic Field widget when the “Additional Info” Textarea meta field is empty.
So, let’s proceed to the Dynamic Visibility section in the Advanced tab and turn on the Enable toggle.
In the Visibility condition type field, we leave the “Show element if condition met” option.
Let’s set up the сondition now. From the Condition dropdown, select the “Regexp” option.
Click the “Dynamic Tag” icon on the right side of the Field selector. Scroll down to the JetEngine section and choose the “Custom Field” option.
In a newly appeared pop-up, pick the meta field from the dropdown (the “Additional Info” field in our case).
The last point — we put “.+” in the Value field.
When working with JetEngine features like Custom Queries, Dynamic Visibility Conditions, or Filters, you might come across the regular expression “.+”, where the “.” (dot) matches any single character, except line breaks, and “+” means one or more of the preceding element.
So, “.+” matches any non-empty value — it’s useful when you want to check if a field contains at least one character (not just spaces or an empty string).
We leave the Context and Data Type fields with their default settings.
Additionally, it’s worth noting that the setup of the Dynamic Visibility feature will be different when the Switcher field is used as the source for the content.
In this case, the “Switcher enabled” Condition should be selected.
Choose the needed custom field in the same way we described above.
Now, let’s see how it works on the front end.
We will check two posts: one has content added to the “Additional Info” meta field and the “Certified Doctor” Switcher enabled, and the second post doesn’t have any of that.
For this post, we see the Dynamic Fields display the data.
The second post has the “Additional Info” meta field empty and the Switcher turned off, so the widgets are hidden.
Now you know how to hide widgets according to the meta fields’ content with the help of the Dynamic Visibility functionality from the JetEngine plugin for WordPress.