Docs/Advanced Topics/Dynamic Data
Dynamic Data
Give a field a conditional rule and it appears only when another field in the same panel section (or metabox) holds the value you specify. Works in both builders and in code.
// Controller field
[ 'id' => 'enable_footer', 'type' => 'switch', 'label' => 'Custom footer?', 'default' => 'off' ],
// Shown only while the switch above is 'on'
[
'id' => 'footer_text',
'type' => 'textarea',
'label' => 'Footer text',
'conditional' => [ 'enable_footer', '==', 'on' ], // [ controller_id, operator, value ]
]
Supported operators
| Operator | Field shows when… |
|---|---|
== | controller value equals the value (compared as strings) |
!= | controller value does not equal the value |
> >= | controller value is greater / greater-or-equal (numeric) |
< <= | controller value is less / less-or-equal (numeric) |
Open a field's editor and set its Conditional rule — choose the controlling field, the operator and the value. Same behavior, no code.
To drive a condition from another sub-field in the same repeater row, give the controlling sub-field a bind key and reference it as the controller — each row then evaluates independently.
The controller and the dependent field must live in the same section (options) or the same metabox — a condition can't reach into a different section or a different metabox. This is the most common reason a conditional field "won't hide" — see FAQ.