Conditional Logic for Fields

Conditional Logic for Fields will allow you to show or hide a field based on the value of another field.

This feature is available in Pods 3.0+

The newest feature that we’ve added to Pods with the release of Pods 3.0 is Conditional Logic for Fields. This allows you to show or hide a field based on the value of another field. Each field type has contextually aware conditional checks which handle numeric or text-based comparisons.

Supported Field Types

  • Text
    • Plain Text
    • Website
    • Phone
    • Email
    • Password
  • Paragraph
    • Plain Paragraph Text
    • Code (Syntax Highlighting)
  • Date / Time
    • Date / Time
    • Date
    • Time
  • Number
    • Plain Number
    • Currency
  • Relationships / Media
    • File / Image / Video
      • Limited conditions:
        • =
        • !=
        • blank
        • not blank
      • Conditional value to use: ID
    • oEmbed
    • Relationship
      • Limited conditions:
        • =
        • !=
        • blank
        • not blank
      • Conditional value to use: The value (simple custom defined) or ID (object
        relationships)
  • Other
    • Yes / No
      • Limited conditions:
        • =
        • !=
      • Conditional value to use: 0 or 1
    • Color Picker
      • Limited conditions:
        • =
        • !=
        • blank
        • not blank
      • Conditional value to use: The value (simple custom defined) or ID (object
        relationships)

Unsupported Field Types

  • Paragraph
    • WYSIWYG (Visual Editor) — There’s an issue with the visual editor syncing with the conditional
      value being checked, this will be worked on
  • Layout Elements
    • Heading
    • HTML Content

Setting up Conditional Logic for a Field

When adding or editing your field, go to the “Conditional Logic” tab and you will find an option to “Enable Conditional Logic”.

Turning Conditional Logic on will now allow you to specify conditional rules to use.

Turning Conditional Logic off again will result in the conditional rules previously set being ignored and the field will become visible in all cases.

Available Logic

Visibility action

  • Show field
  • Hide field

Rule Requirements

  • Any – Any rules met will trigger the visibility action
  • All – All rules met will trigger the visibility action

Conditional Rules

  • is (=) – Whether the field value exactly equals the text value provided
  • is not (!=) – Whether the field value does not exactly equal the text value provided
  • is blank – Whether the field value is empty (Yes / No fields are excluded)
  • is not blank – Whether the field value is not empty (Yes / No fields are excluded)
  • Numeric rules
    • greater than (>) – Whether the field value is greater than the text value provided
    • greater than or equal (>=) – Whether the field value is greater than or equal to the text value provided
    • less than (<) – Whether the field value is less than the text value provided
    • less than or equal (<=) – Whether the field value is less than or equal to the text value provided
  • Text rules (excluding File / Image / Video, Relationship, Yes / No, Color Picker)
    • contains – Whether the field value contains the text value provided
    • does not contain – Whether the field value does not contain the text value provided
    • starts with – Whether the field value starts with the text value provided
    • does not start with – Whether the field value does not start with the text value provided
    • ends with – Whether the field value ends with the text value provided
    • does not end with – Whether the field value does not end with the text value provided
    • matches pattern – Whether the field value matches the Regular Expression pattern from the text value provided
      • Patterns must exclude the wrapper character, so /\d/ would just be \d
    • does not match pattern – Whether the field value does not match the Regular Expression pattern from the text value provided
      • Patterns must exclude the wrapper character, so /\d/ would just be \d

Conditional values used by field type

  • Text-based fields are simple, they are what they are for input.
  • Date fields always use values that are in ISO 8601 format for value comparisons.
    • For date/time fields, the format for March 1st, 2023 at 2pm would be 2023-03-01 14:00:00
    • For date fields, the format for March 1st, 2023 would be 2023-03-01
    • For time fields, the format for 2pm would be 14:00:00
  • Relationships have different values referenced depending on what kind of object is related to.
    • For objects like Posts or Users that have IDs, the ID value will be what you want to reference in your conditional.
    • For simple objects like custom defined lists or predefined lists, the value will be what you want to reference.
      • If no values are set in a format like value|Label for custom defined lists, then the label automatically is referenced as the value.

Conditionally fields that are hidden do not save

Currently, fields that are conditionally hidden and submitted through forms will not be saved. If a field was hidden by Conditional Logic, it will be excluded from the saving process itself when submitting forms.

If you are saving values manually with PHP, conditional logic will not be checked.

You can enable saving of all fields with conditional logic submitted through forms by bypassing that logic using the below filter.

// Enable saving conditionally hidden fields.
add_filter( 'pods_api_save_pod_item_exclude_conditionally_hidden_fields', '__return_false' );

Displaying values with Conditional Logic

If you get the value of a field or display it, nothing will change even if the conditional logic has hidden that field in forms. You will still need to use your own logic to handle whether to display that field’s value.

Extending Conditional Logic (JS)

There is not currently a way to hook into the JS side of the conditional logic handling. This will be added in a future release.

Extending Conditional Logic (PHP)

If you want to support your own custom rules, there is a PHP hook to handle this (only runs on form submit saves on the PHP side). This filter looks like this and you can take that Conditional_Logic object and adjust rules with $logic->set_rules( $rules_array ) and other available methods from that object.

/**
 * Allow filtering the conditional logic object used for a Whatsit object.
 *
 * @since 3.0
 *
 * @param Conditional_Logic $conditional_logic The conditional logic object.
 * @param Whatsit           $object            The object data.
 * @param string            $action            The action to take (show/hide).
 * @param string            $logic             The logic to use (any/all).
 * @param array             $rules             The conditional rules.
 */
$conditional_logic = apply_filters( 'pods_data_conditional_logic_for_object', $conditional_logic, $object, $action, $logic, $rules );

Other Helpful Documentation on Working with Fields in Pods

Avatar Field

Extends User Profile with a Gravatar field that is managed under the Media Library as opposed to using Gravatar.com

Code (Syntax Highlighting) Field

The Code (Syntax Highlighting) field is used for multiple line code content.

Color Picker Field

The Color Picker field is useful in situations where a color needs to be able to be chosen and customized.

Currency Field

The Currency field is used to store numeric, integer, and float currency amounts.

Date / Time Field

The Date / Time field is used to store a date and time value with an easy to use date / time input.

Date Field

The Date field is used to store a date value with an easy to use date input.

Date time fields redirect

Email Field

The Email field allows you to store email addresses with additional validation checks.

File / Image / Video Field

The File / Image / Video field is used to store a relationship to Media attachment(s).

Heading Field

The Heading field is not a normal input field, it will output Heading text between your normal form fields to help organize the form.

HTML Content Field

The HTML Content field is not a normal input field, it will output as HTML itself between your normal form fields to help organize the form.

oEmbed Field

The oEmbed field is used to store a single URL that will use the oEmbed protocol to display remote content.

Password Field

The Password field is used to store single-line text with a basic password input form field.

Phone Field

The Phone field is used for telephone numbers in various formats.

Plain Number Field

The Plain Number field is used to store numeric, integer, and float values.

Plain Paragraph Text Field

The Plain Paragraph Text field is used for multiple line text values.

Plain Text Field

The Plain Text field is used for Simple Plain Text Values like a first name, last name, alphanumeric ID or value.

Relationship Field

The Relationship field is used to store related items on various objects in WordPress.

Settings: Advanced

Provides access to the Advanced field options when editing a field.

Settings: Field Details

Basic Field Settings (Label, Name, Description and Field Type) that apply to all Fields created in Pods.

Settings: Reserved List of Names

There are certain names you cannot use for Pod, Group, or Field names in Pods because they are reserved in WordPress or Pods for other uses.

Simple Repeatable Fields

Simple Repeatable Fields will allow you to repeat many different types of fields.

Time Field

The Time field is used to store a date value with an easy to use time input.

Website Field

The Website field is used to store a URL or Website Address or Link to a Website.

WYSIWYG (Visual Editor) Field

The WYSIWYG (Visual Editor) field is used for multiple line HTML content.

Yes / No Field

The Yes / No field offers customizable labels and display options for checkbox, radio buttons, or a drop-down input.