Problem: I am using the Real Estate reference site as an example. When creating a House post, I would like to select a State, then select a City from a list of Cities in that State.
Solution:
In wp-admin, there's no built-in way to do this. There is no "grandparent" post selection in post relationships, only parent selection. You could add the state abbreviation to each duplicate city post title:
City - "Kansas City, KS"
City - "Kansas City, MO"
In Forms, there is a more complex solution:
- Create a generic select field that includes an option for each State. The value of each option should be the State post ID. You can use a View of States to create the options for the generic field.
- Next create one generic select field for each State. Add options for each City in that State. You can use a View of Cities filtered by post relationship to create the options for the generic fields.
- Use Conditional Field Groups to show and hide the City select fields based on the selected State.
- Then capture the selected City post ID using the Forms API, and use the Post Relationships API to link the House and the City.
Relevant Documentation:
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data