FAQ

Just Custom Fields

Can I Show/Hide Fields Based on Some Conditions?

When developing big applications on WordPress using the Just Custom Fields plugin, we are often faced with the problem of having a large number of fieldsets on some custom post types. It complicates the management of content on the website.

To resolve this issue there is a very interesting fieldsets feature in the plugin – “Visibility Rules”. Thanks to these rules we can hide fieldsets on the edit post page depending on the conditions. Such an approach allows the process of editing and creating content to be simplified.

The rules of visibility settings have several conditions:

  • Show/Hide
  • Join condition with previous rules with boolean operator: AND/OR
  • Based on: Taxonomy/Page template
  • Conditional Taxonomy terms or Page templates

First of all, it’s important to explain how our rules will work. For example, what if we need to display a fieldset only when a category is chosen? To allow this happens we create new rule: it should “Show” the fieldset,  to be Based on “Taxonomy” of Type “Category” with specific category set. This rule will display our fieldset only when the category is chosen. In all other cases, this field will be hidden.

Also to display the fieldset, there is an opportunity to create several rules which will be connected by conditions of “Join condition with previous rules with operator” (can be AND, OR). All rules after the first one ignores visibility option (show/hide) and follow this option from the first rule. All rules join to each other after previous rules were “merged”.

If we try to write down the operation which applies to the fieldset with multiple rules it will look as follow:

(((rule1 AND rule2) OR rule3) OR rule4)*
* Operators AND, OR are set just as an example. They will match your settings set for visibility rules.

We see that each rule is added to the previous calculated result of previous rules.

For more details of how the visibility rules work, you can watch the instructional video: