Skip to content

Conditional Logic

Show or hide fields dynamically based on the value of other fields using conditional logic.

Conditional logic lets you show or hide a field based on the current value of another field in the same field group. It works both in the WordPress post editor and on user profile pages.


How It Works

When you configure conditional logic on a field, OneMeta checks the value of a specified sibling field in real time. If the condition is met, the field is shown. If not, it is hidden. The field is still saved when hidden — it is only visually toggled.


Setting Up Conditional Logic

In the field builder, expand the Advanced Settings for any field and enable Conditional Logic. Configure three values:

SettingDescription
FieldThe key of the sibling field to watch
OperatorThe comparison operator
ValueThe value to compare against

Supported Operators

OperatorDescriptionExample
==Equal toShow when layout equals grid
!=Not equal toShow when status is not draft
containsContains text (case-insensitive)Show when title contains sale
!containsDoes not contain text (case-insensitive)Show when tags does not contain hidden

PHP Export Example

When you export a field group as PHP, conditional logic is included in the exported config:

php

'my_field' => [
    'type'        => 'text',
    'label'       => 'Custom Subtitle',
    'description' => 'Shown only when layout is set to Hero',
    'conditional' => [
        'field'    => 'layout',
        'operator' => '==',
        'value'    => 'hero',
    ],
],

Practical Examples

Show a colour picker only when a toggle is on:

php

'brand_color' => [
    'type'        => 'text',
    'label'       => 'Brand Colour',
    'conditional' => [
        'field'    => 'use_brand_color',
        'operator' => '==',
        'value'    => '1',
    ],
],

Hide a field when a select is set to a specific value:

php

'external_url' => [
    'type'        => 'url',
    'label'       => 'External Link',
    'conditional' => [
        'field'    => 'link_type',
        'operator' => '==',
        'value'    => 'external',
    ],
],

Show a field only when a text input is not empty:

php

'subtitle' => [
    'type'        => 'text',
    'label'       => 'Subtitle',
    'conditional' => [
        'field'    => 'title',
        'operator' => '!=',
        'value'    => '',
    ],
],

Notes

  • Conditional logic is evaluated in real time in the browser — no page reload required
  • A hidden field’s value is not cleared when the field is hidden — it remains saved
  • You can only reference fields within the same field group
  • contains and !contains operators are case-insensitive
  • Conditional logic is fully supported inside Repeater sub-fields

Was this article helpful?

On This Page