Skip Navigation

Conditionally Display Custom Fields in WordPress Backend

Toolset allows you to display custom fields in the backend editor only when certain conditions are met. You can do this for a specific field or a whole group of custom fields.

Conditionally display specific custom field

Sometimes, it only makes sense to display a custom field when another field has a specific value.

Let’s consider an example on a real estate site. You could have a custom checkbox field to indicate if the property has a swimming pool. You could then have another field to enter the swimming pool size. It only makes sense to display the swimming pool size field if the house has the swimming pool and the checkbox field is selected.

Steps to conditionally display a specific single custom field:

  1. Edit the group of custom fields that holds the specific field you want to display conditionally.
  2. Expand the options for the custom field and in the Conditional display row, click Set condition(s).
Button for setting the conditional display of a specific custom field
  1. In the pop-up dialog that appears click Add condition. You can add multiple conditions for the same field.
  2. Use the dropdown to select the custom field you want to check against.
  3. Set the condition operator and then the value you want to check for.
  4. When you’re done, click Apply.
Setting the conditions for displaying a custom field

And that’s it, now that custom field will only show up in the editor if the conditions are met.

Conditionally display a group of custom fields

Sometimes, you might have a group of custom fields that should be available only in certain conditions.

Again, let’s consider an example of a real estate site. You could have a “Property Type” taxonomy for selecting if the property is a house, apartment, or office. It would make sense to display different group of custom fields for different types of property. For example, houses need fields for garden information but apartments don’t.

You can display groups of custom fields based on the following conditions:

  • Post Type – display group only for certain post types
  • Taxonomies – display group only when specific taxonomy terms are selected
  • Templates – display group only for posts that have a specific template assigned
  • Custom Fields – display group only when another custom field has a specific value

Steps to conditionally display a group of custom fields:

  1. Edit the group of custom fields you want to display conditionally.
  2. Expand the Settings for… section at the top of the page.
  3. In the Appears on section, click the Edit button.
Button for setting the conditional display of a group of custom fields
  1. In the pop-up dialog that appears, select the conditions for displaying this group of fields.
Setting the field group to display only when a specific taxonomy term is selected
  1. Finally, look in the main settings for the field group. Under Use Field Group, make sure to select the when ALL conditions are met option.

That’s it, now the whole group of custom fields will only display in the editor if your conditions are met.

Important: if the conditions are based on taxonomy terms or templates, the editing page needs to be reloaded for the field group to be shown or hidden.