Skip Navigation

[Closed] State and City dropdowns for CRED

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.

Author
Posts
#1672931

Hi,

I'm building a directory site.

When creating a listing I'd like the client to be able to click a state dropdown, followed by a city dropdown when they input the address for their listing.

I'd like the url slug to include the state and city entered by the client, so the URL would be something like: hidden link

Lastly, I'd like the end-user to be able to filter listings with a state/city pair of dropdowns, similar to the real estate site example you have here: hidden link

I imagine this has been accomplished, but I haven't found the correct thread for help yet.

Thanks!
Eric

#1673691

Christian Cox
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Hi, the state and city dropdowns in the Real Estate site are accomplished by creating custom post types for City and State, and creating custom posts for each possible city. Then you would have to manually create post relationships between States, Cities, and posts. In other words, the options in each dropdown are limited to the posts you create in wp-admin, not the entries submitted by selecting from the address field. You can create a free account at https://discover-wp.com to examine the backend structure of the Real Estate reference site. In most dynamic situations, this isn't ideal, you would not want to manually create a city post for each possible city and a state post for each possible state, then create post relationships between those and the location for each post. Furthermore, the URL structure you've requested isn't something Toolset is capable of producing out-of-the-box, and will require custom code. So the short answer is I don't think Toolset is the right tool for a job that requires a fully dynamic system and the URL structure you mentioned, given the amount of custom code and backend work that would be required to accomplish what would be required for a fully dynamic site. You would have to implement a considerable amount of custom JavaScript to break out the state and city from the address field, and a considerable amount of PHP to link those posts with post relationships, not to mention the custom URL rewriting code you would need. The JavaScript required to separate address components is examined in this ticket: https://toolset.com/forums/topic/separating-content-from-the-address-field/

So given those limitations, I'd like to get your feedback. If this undertaking is something you feel comfortable with, I can provide information about any APIs you 'd like to utilize including our post relationships API. However, the JavaScript required here is outside the scope of support that is provided in the forums.

#1673951
Screen Shot 2020-06-23 at 12.19.41 PM.png

Thanks for the detailed reply.

I was thinking the states and cities could be handled using taxonomies, and that I could figure out a function to customize the URL for just the listing custom post type. It seems like populating the cities taxonomy would be the most difficult thing since there are thousands of cities. Maybe I need to rethink that part...

We don't want to post the clients' full address. We're hoping to do something like craigslist does, with cross streets, city, zip, so the end-user can get a general idea of the listing location. See upload.

#1675655

Christian Cox
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

I was thinking the states and cities could be handled using taxonomies
To display two separate front-end filters for city and state you must use two separate taxonomies, as opposed to a single hierarchical taxonomy with States as top-level terms and Cities as sub-level terms. Just so you are aware of how that would have to be implemented in the current system.

We're hoping to do something like craigslist does, with cross streets, city, zip, so the end-user can get a general idea of the listing location.
Okay understood. There's no built-in approximation feature for marker placement. You must specify a mappable address or a specific latitude/longitude pair to place a marker on a map. I think some alternatives might be:
- Use one address field for the full address, and a second address field to specify a nearby location. Something like a business, park, neighborhood or other place of interest would work. Place the map marker at that nearby location instead of the actual location. This solution works without any custom code, but does require an extra step during the process of capturing the data for a post.
- Write a custom shortcode that randomizes the lat/long pair of a geocoded address. Return the randomized values so you can use them in the marker shortcode. This is probably the simplest, most practical code-based solution. You can get the lat/long of a geocoded address using the Types field API: https://toolset.com/documentation/customizing-sites-using-php/functions/
- After the actual address is geocoded, you'll have access to the latitude and longitude of that location. Round the numbers off by a decimal place or two, or randomize the values a bit, then submit a reverse geocoding request to the Google Maps API to find a street address closest to that lat/long location. Store the response in another address custom field, and use that address to display a marker on the map. This is pretty advanced stuff, because you'll be using custom code to communicate directly with the Google Maps APIs for Reverse Geocoding.

#1675697

FYI, I found a very interesting plugin: hidden link
I was able to easily craft a URL that includes the post type, a taxonomy term (for state), a custom field (for city) and the post name. Pretty nice so far.

I'm going to experiment with map marker placement next. I'd like to keep this thread open for a bit if that's ok.

Thanks

#1676635

Christian Cox
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Of course, I'll stand by for your feedback.

The topic ‘[Closed] State and City dropdowns for CRED’ is closed to new replies.