Custom fields belong to a post type, but you can make a field appear on the add listing form only when certain categories are chosen. GeoDirectory does this with conditional fields.
Set up a category condition
- Find the ID of the category. Go to Places > Categories and hover over the category name, or open it and look for
tag_ID=in the address bar. - Go to Places > Settings > Custom Fields and open the field you want to limit, for example WiFi.
- Open the Conditional Fields section in the field settings and add a rule.
- Set the rule to show, if Category, contains, and enter the category ID. Use a comma separated list for several categories, for example
12,15. - Save the field.
Now the WiFi field stays hidden on the add listing form until the user ticks one of those categories. If the field is shown on the details page, it only appears for listings that have a value, so a restaurant with no WiFi entry will not show an empty WiFi line.
You can also hide a field by category, or base the rule on the Default Category instead. How to use conditional fields settings? covers every condition.
Things to keep in mind
- Do not make a field required if it is hidden for some categories. A hidden required field will stop the form from submitting.
- With Pricing Manager, each field also has “Show only on these price packages”, so you can combine a package and a category rule.
- If your categories need mostly different fields, a separate post type for each group is often easier to manage. See How to Add a New Custom Post Type?.