Conditional logic
4 min read
Conditional logic shows a field only when other fields have certain values. It runs on the edit screen as the editor types; it does not change what is stored or what your theme prints.
Set it up
- Open the field's Advanced options and go to the Conditional logic tab.
- Turn on Enable conditional logic. (While it is off the tab says
When enabled, this field is shown or hidden based on the values of other fields in the same group.) - Click Add condition. A condition has three parts:
Part | What you choose |
|---|---|
Field | Another field on the same level ( |
Operator | Which operators appear depends on that field's type, see below. |
Value ( | What to compare with. Not needed for Has value and Is empty. |
- Choose how several conditions combine: Match: and / or of the following conditions.
- and: all conditions must be true.
- or: at least one must be true.
- Save the group.
If the group has no other fields the tab says No other fields are defined in this group. Add more fields to use conditional logic. At most 20 conditions are kept per field.
Operators
Operator | True when | Offered for |
|---|---|---|
Has value | The other field is not empty. | every type |
Is empty | The other field is empty. | every type |
Equals | One of its values is exactly the Value. | every type except those stored as JSON |
Not equals | None of its values is the Value. | same |
Contains | Its text contains the Value. | text-like and choice types |
Does not contain | Its text does not contain the Value. | text-like and choice types |
Greater than | The number is larger than the Value. | numeric types (Number, Range) |
Less than | The number is smaller than the Value. | numeric types |
Fields stored as JSON (Checkbox list, relationships, Group, Repeater, Gallery, ...) only offer Has value and Is empty.
What to type in Value:
Field type | Value |
|---|---|
Text, Text area, Email, URL | The text. |
Number, Range | The number (the input only accepts numbers). |
Select, Radio buttons, Button group | The choice's value (the stored value), not its label. |
True / false |
|
Which fields can I use?
Conditions only see sibling fields: fields on the same level of the same group. Inside a Group or Repeater a condition looks at the other sub-fields of the same group value or the same repeater row. Conditions cannot look at fields in another group, or reach from a sub-field to a root field.
If a condition names a field that no longer exists, that condition counts as true.
What happens to hidden fields
Question | Answer |
|---|---|
Is the value of a hidden field deleted? | No. Hiding never deletes data: a hidden field still posts its value and the value stays in the table. |
Is a hidden field required? | No. A hidden field is never required, in the browser and on the server. |
Do hidden fields show up in your theme? | Yes. Conditional logic is an editing aid only; if your template must respect it, check the other field's value in your template code. |
The server evaluates the same conditions (for the required-field check after saving), so a required field that is hidden at save time does not trigger Saved, but these required fields are empty.
Example
A "Product details" group where Sale price only appears when On sale is ticked:
- Add a True / false field
on_salelabeled On sale. - Add a Number field
sale_price. - On
sale_price: enable conditional logic, add the condition On sale · Equals ·1.
Through the REST API the same condition looks like:
{
"key": "sale_price", "label": "Sale price", "type": "number",
"conditional_logic": {
"enabled": true,
"relation": "and",
"rules": [ { "field_key": "on_sale", "operator": "equals", "value": "1" } ]
}
}Troubleshooting
Problem | Fix |
|---|---|
The field is always visible | Check that Enable conditional logic is on, and that the condition's field still exists in the group. |
I cannot pick the field I want | Only sibling fields at the same level are offered. Move the fields to the same level. |
For a Select field, Equals never matches | Type the choice's stored value, not its label. |
Greater than is missing | The referenced field is not numeric. |
Still stuck? Contact support