Conditional fields
Conditional fields allow you to create more dynamic and personalized submission forms for your post types. By showing or hiding fields based on user input or other factors, conditional fields can streamline the process and improve the user experience.
For example, consider a form for event registration. If the user selects “Yes” for a checkbox indicating they are bringing a guest, a conditional field may appear asking for the guest’s name. If the user selects “No,” the field would remain hidden. This allows the form to adapt to the user’s choices and display only the relevant fields.
Conditional fields can be particularly useful when dealing with complex forms or content structures where displaying all fields at once would overwhelm the user or create unnecessary clutter. By presenting fields dynamically, based on user actions or specific conditions, conditional fields help simplify the interaction and make the form or content more intuitive and focused.
How to create conditions
On the Post type editor > Fields, you can configure the fields available for your post type.
Once a field is added, you can enable conditional logic for it.
To activate conditional logic for a specific field, click on the field. In the field popup, go to the “Conditional logic” tab and turn on the option “Enable conditional logic for this field?”
You can add multiple conditions to the same group or create multiple groups for different conditions.
Conditions within the same group use “And” logic, while different rule groups use “Or” logic.
“And” means all conditions must be met for the condition to pass, while “Or” means that at least one of the rule group conditions must be met for the condition to pass.
When adding a condition, the first option is to select another post type field that you want the current field to be conditioned by.
Next, select the condition. Available conditions include:
- Is empty
- Is not empty
- Equals
- Not equals
- Greater than
- Greater than or equal to
- Less than
- Less than or equal to
Depending on the condition selected, additional options may appear. For example, if you choose “Less than,” a number input may appear to specify the value.
Let’s consider an example:
Suppose you are configuring a Tours post type, and depending on whether the tour has a guide or not, you want to display a field to specify the guide’s language.
You can create a switcher field named “Guide language” and a text field named “Specify language.”
In this case, you apply conditional logic to the text field by clicking on the field and enabling condition logic.
Select Source: Guide language
Condition: Is true.
On the post submission form, depending on whether the user has enabled the Guide language switcher, the Specify language field will either appear or not appear.