[Resolved] Easy way to select State & City locations for each instance of custom post type
This thread is resolved. Here is a description of the problem and solution.
Problem:
Solution:
To implement such functionality - You should check this example:
=> http://real-estate-wordpress.discover-wp.com/
- Please check “State” and “City” dropdowns with search form.
I'm developing a directory site and so far Toolset is working awesome.
The only thing left for now is that I work at national level. I need my users to select which state their office is in, and then in which city *inside that state*.
What would be the best approach to achieve this?
I've thought of:
1. Use a custom taxonomy with each State as parent and the Cities of each state as children.
-> Problem: upon creating their office, the user will be presented with a veeeery long list to select from, so it's a bit unusable
2. Use two custom taxonomies: one with State, and another one for Cities
-> Problem: I would need to filter the cities dropdown to only load cities related to that state and I would have to set that relationship somehow
3. Use a custom post types for State and Cities and relate each post to each one of them.
-> Problem: I guess it would be less performant and I would have, again, to set up that relationship between State and its cities manually and filter on the frontend for the user to select.
As I see Toolset is being used for lots of directory sistes, is there any way to easily achieve this?
Thanks a lot!
P.S: This is all guessing we can't extract the State and City from Google Maps (which I'm using), as that would be awesome.
Hello. Thank you for contacting the Toolset support.
The only possibility to implement such State and City dependent filter is when you configure the State and City as post types which is having one to many relationships.
So, in your case the following point is a possible way:
3. Use custom post types for State and Cities and relate each post to each one of them.
-> Problem: I guess it would be less performant and I would have, again, to set up that relationship between State and its cities manually and filter on the frontend for the user to select.
To implement such functionality - You should check this example:
=> hidden link
- Please check “State” and “City” dropdowns with search form.
Thanks a lot for helping. I didn't know about the discover-wp sites, greate resource.
I've recreated that but unfortunately, when the user submits a new office/house through CRED I still get a LONG list of cities (I have more than 6000). At least it is searchable, but still no context of the State.
I see with filters we can implement the "select parent, then select child" behaviour with '[wpv-control-post-relationship' shortcodes. Is there any way to do something similar with CRED where my users select first the State then the City in that previously selected State?
No - There is no way to add such dependent dropdown with Toolset forms. At the moment its possible with only views when its added as filter as you already described.
Thanks a lot for the feedback Minesh. I'll file a request or upvote since I've seen other threads where this was mentioned too.
For reference, if this is of use to anybody, whay I may end up doing is creating a hierarchical taxonomy with States as parents and Cities as children. Then I'll add two select boxes in the form and with javascript I'll filter and leave just the parents in the first select (States) and leave just the children in the second one (Cities) that will filter them based on the value of the first one.
Not the most convenient thing but not too hard for someone with Javascript knowledge. I've tried the submission and both get submitted correctly so we end up with the parent and child category and subcategory checked in the backend.