Skip Navigation

[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.

To know more and learn about how the "State" and "City" drop-down setup, You should register the test site on http://www.discover-wp.com:
=> https://discover-wp.com/site-types/bootstrap-estate-layouts/

Relevant Documentation:

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by jacoboG-2 5 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#1369833

Hello,

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.

#1369959

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

To know more and learn about how the "State" and "City" drop-down setup, You should register the test site on http://www.discover-wp.com:
=> https://discover-wp.com/site-types/bootstrap-estate-layouts/

#1370161

Hi Minesh!

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?

Thanks a ton!

#1370491

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

You can file a feature request and our Devs will review it
=> https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1370503

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.

Hope this helps someone sometime.

Cheers!

#1370505

Thanks!