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.
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:
- Edit the group of custom fields that holds the specific field you want to display conditionally.
- Expand the options for the custom field and in the Conditional display row, click Set condition(s).
- In the pop-up dialog that appears click Add condition. You can add multiple conditions for the same field.
- Use the dropdown to select the custom field you want to check against.
- Set the condition operator and then the value you want to check for.
- When you’re done, click Apply.
And that’s it, now that custom field will only show up in the editor if the conditions are met.
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:
- Edit the group of custom fields you want to display conditionally.
- Expand the Settings for… section at the top of the page.
- In the Appears on section, click the Edit button.
- In the pop-up dialog that appears, select the conditions for displaying this group of fields.
- 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.
- Using Custom Fields vs. Taxonomy
- Using Post Reference Field to Set-Up One-to-Many Relationships
- Adding a Custom Taxonomy to WooCommerce Products
- How Content is Displayed
- Adding Custom Posts
- When and Why You Should Use Custom Types
- Creating a Custom Taxonomy
- Creating Custom Fields
- Creating a Custom Post Type
- What Are Custom Types and How They Work
- Convert existing custom types and fields to Types control
- Limitations on HTML Content in Post Fields