Skip Navigation

[Resolved] Location Data Assignment in C&B Reference Site

This support ticket is created 3 years, 4 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9: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: Africa/Casablanca (GMT+01:00)

Author
Posts
#2071685

Don

Tell us what you are trying to do?

Hello, I used the Toolset framework installer to install the C&B Reference site since, on the demo, it appeared to offer the functionality I asked about in another support thread, namely to be able to filter results based on individual location fields like "State" and "City" in a view despite only using the single autocomplete Address field in the Toolset Map addon during post creation.

But I quickly hit a wall and need help understanding how this data is collected and assigned to fields and BY WHO and WHERE (ie listing poster on front end OR admin on backend) ? The demo looks and works great with the default fields but my own NEW test listings quickly showed me that there was more going on here than it looks like on the front end.

1) prior to changing anything in the admin, on front end I created a new listing but selected a location in the autocomplete address field that was in a different state and city than the default demo listings.
2) On front end when searching properties/using the default view, although my new listing displays in the map above the view section my NEW "State" is not available in the dropdown.
2) Ok, so now i went into admin and under the "State" taxonomies" I manually added my NEW State with title and abbreviation like the default ones. In view my new state still does not display in the state filter dropdown.
3) Just to be safe, I created ANOTHER new listing with different address but in the same "New" state. The new state STILL does not show up in the State filter dropdown in the view.
4) Ugh. I double checked on the front end form, nope, there is no other field to manually select a "State" and "City" value in addition to the autocomplete location field.
5) IF I edit a listing as ADMIN though, there IS a section at bottom of the form called "City Property", which is NOT available on the front end form, where I can "Add new City" or "connect existing city" or disconnect if ones is assigned.

So now I am REALLY confused HOW, WHERE and by WHO the values for a State and City are assigned to each and every listing that is posted via a FRONT END form! I really hope that I am missing something and that there is a easy way for each and every post to assign the relevant state and city values for an address given in the autocomplete address field and NOT that I, as admin, have to manually connect each post with a city after the fact.....

#2071691

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting Toolset support.

Actually, you as an admin need to create the relevant City posts, State posts, and manually connect them to the Property post. The assignment is not performed automatically by Toolset Maps. I'll explain later why this is not a built-in Toolset Maps feature.

The new state does not appear on the dropdown, most probably, because it is not connected to a city post. The city post needs to be connected to at least one property post.
For the new properties, you have created, create their relevant city posts in the admin panel. Connect the cities to these properties, and to the new state. This would make the new state appear on the dropdown filter, and the new cities will appear on the city dropdown filter on the view.

Why Toolset does not offer a default way to split the components of address(country, state, city, etc.) into separate custom fields, taxonomies, or even post types?
Because the Maps APIs(Google or Microsoft Azure) responses do not always contain all these components. They may have the country, but not the state, or the state but not the city, and the responses can have different designations for city/state. Check for example the possible return values from Google Maps.
hidden link

Toolset Maps uses two pieces of information:
- Formatted Address: Stored as a text custom field in the post meta table.
- Coordinates: Stored as geolocation data in a Toolset specific table. This table is used for distance searches.

I hope this answers your question and gives you some insights about Toolset Maps. Let me know if you have any specific questions.

#2071693

Don

thank you SO much for the prompt and thorough clarification!

I can understand HOW it works better now but, to clarify, if I go through these steps and connect city posts to ONE new "post" and to a state, will FUTURE front end form posts AUTOMATICALLY use these known fields? OR do I as admin have to MANUALLY assign each and every new post to a city post /state? That would be fine if I have to do it "once" for each city/state but to have to do each and every time for every new post would be, well, daunting....

thanks again for the time and professional walk through!

#2071709

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Unfortunately, you will need to MANUALLY ensure that every new post is assigned to its city post, and each city post is assigned to its state post.

The automatic assignment will require custom code that will:
- Get the city and state from the Maps API in a second call. Because Toolset Maps does not provide a way to share this information. Maybe it would in the future.
- Check if the city and state already exist, otherwise create them.
- Perform the assignment property<>city, city<>state.
Such custom code can use:
- cred_save_data hook for posts that are created using a Toolset form: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
- save_post hook for posts that are created on the backend: https://developer.wordpress.org/reference/hooks/save_post/
- Maps API to get the city and state: hidden link or hidden link
- get_posts to ensure city/state exists: https://developer.wordpress.org/reference/functions/get_posts/
- wp_insert_post to create city/state posts if needed: https://developer.wordpress.org/reference/functions/wp_insert_post/
- toolset_connect_posts to perform the relationship assignment/link: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

Please note that custom code is beyond the scope of the support forum. If you are not comfortable with programming consider hiring a developer https://toolset.com/contractors/
https://toolset.com/toolset-support-policy/

All the best,
Jamal

#2071819

Don

ok thank you for clarifying.... i had assumed that the state and cities were being saved and treated as taxonomies under the properties post type, not as independent post types that have a relationship assigned manually on the back end. That wont work for my needs, would be impractical to keep up with that.... so was looking at doing them as a location taxonomy, with states as parent terms and children states as child terms.... But it looks like it is not possible to display child terms in a SEPARATE dropdown, based on which parent term is selected... ie, basically a conditional display, with a lot more manageable list o parent terms in direct logical order and, in another dropdown, all child city terms in order based on the selected parent state term. If THAT is possible, in a form AND as a filter for a view, to have dropdowns (if not checkboxes for each taxonomy level) that would be a great option. Otherwise, although it is not near as efficient or organized, i might have to just create a custom fieldsfor states, and a custom field for cities, and go that route....

#2071899

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

You are right, it is not possible to have two dropdowns for parent and child terms in a custom taxonomy. You can only have one dropdown per taxonomy.

The demo site used a one-to-many relationship because that's the only way possible, out of the box, to have dependent dropdowns. Once a state is selected, the cities dropdown will display only the child cities of the selected state.
Also, because currently, views can only filter using ONE relationship. The only case when it can use multiple relationships is using "hierarchical" one-to-many relationships. We call them ancestors.

I may agree, depending on the project requirements, maybe a custom field data model is more suited. For sure, queries based on custom fields are not as efficient as queries based on taxonomies. The queries that are based on Toolset relationships are as efficient as those based on taxonomies because Toolset uses its own tables to store the relationships.

I'll remain at your disposal. Let me know if you have any further questions.

#2071927

Don

Thank you for the additional info. Before I get too far along here, and by not completely understanding and being able to use the full potential that toolset offers missing out on "better"/more efficient and perhaps even "easier" solutions to my goals, I am going to attempt to clarify what I want to achieve and, maybe you see a solution and can recommend something so I dont naively choose the wrong way to achieve it.

1) My site is for housing, saturated market I know but it is what it is.

2) Users on the FRONT END being able to easily define the location/set all relevant location data fields during ad posting process is super important. The C&B demo gave me the impression it did what I want but, through clarification from support, I see that it requires a HUGE amount of admin-side post to post mapping.... not realistic if/when there are numerous new posts per day.

3) The toolset map addon currently only supports saving a SINGLE, combined address field. This i problematic for me since 1) there is no available "separate" location data to display flexibly (like just the city name, just the zip code etc) AND gives the user no way to FILTER by LOCATION aside from the radius search, ie cannot simply choose a "State" to filter by, then choose a "City" within that state to filter by. So, I have decided to use my own solution during listing placement, to get the location data, still save a complete address field to the map addon "Address" field but also save the other data to individual fields. BUT, although it is clear that saving info like street address and zip code as "Custom Fields" makes sense, I am not sure how best to deal with the States and Cities. Doing them as a "Taxonomy", due to the inherent hierarchy, makes a lot of sense..... but since ALL state AND City "Terms" would have to be in a SINGLE dropdown, that would be a HUGE dropdown list for users (well, not on the listing placement form since would be assigned via hidden fields from the custom autocomplete but WOULD be unavoidable on the "View" page as filter, see below). I can treate the States and Cities as "Custom Fields" but is a lot less efficient to query and lose the natural "Hierarchy" of state to city relationship.

4) Users on the FRONT END being able to EASILY FILTER based on location is also important. I have been reconsidering the BEST way to present Users efficient Filter options, since the method on the real estate demo requires backend manual mapping of post type relationships which wont work for my needs. As mentioned in point above, having a taxonomy dropdown filter for location, with ALL states AND cities in it would be overwhelming for a user on front end when filtering a view (even if every state had "only" one city, that would be a dropdown with 100 lines!).... so that wont work.

5) I am also not clear on how many taxonomies can be filtered simultaneously within a single view..... for example if for a "Properties" Post type I WERE to use the heirarchal taxonomy for location (ie state as parent, city as child) AND also a taxonomy for "Property Type" (with Terms like "House" , "Apartment", "Condo" etc) AND also a taxonomy for "Listing Type" (with terms like "For sale", "For Rent", "roommates" would a user be able to filter the view for the "Properties" using ALL of these taxonomies combined? Or would it only filter based on ONE taxonomy or the other, and then only further filter based on custom field selections?

6) What are the possibilities to use the taxonomy terms and/or selected custom fields in a URL for a page with a view? By default but also if using an addon like Permalinks Pro? Ideally I would like my URL structure on page with a post type view to reflect the information something like this: myurl/(pageslugforposttype)/(slugforselectedState-taxonomyORcustomfield)/(slugforselectedCity-taxonomyORcustomfield)/(slugforselectedPropertyType)/(....and then slug for any selected single post)

Is THAT possible with toolset default or at least by using permalinks pro in connection with the toolset view, post types and/or taxonomy and custom field settings?

Sorry for the long winded explanation, hopefully it is more clear, helps me decide the best route to go AND hopefully also helps others later on interested in similar....

#2071957

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

I'll try to comment on each of the points below by their numbers.

1) Well, nothing to comment on here 🙂

2) Unfortunately, that is the case. The Toolset Maps address field does not offer a way, yet, for splitting the components of an address, and store them in different areas. Without custom code, administrators' intervention is mandatory.

I am not aware of any solution on the market that offers that. There are numerous WordPress themes and plugins that support geolocation for listing sites, but I am not aware of any that can use a Maps API(Google or else) and allow to split the address components into different fields or taxonomies.

3) I agree, the dropdown for a hierarchical taxonomy will become a very long list and a not very friendly interface. You can use a 3rd party Javascript library, such as Select2, but it would be very difficult to produce a smooth user experience.

Maybe using two taxonomies, one for states, and the other for cities, and leveraging Select2. But, making the cities dropdown depend on the states dropdown will not be trivial.

Another solution might be using a hierarchical taxonomy. But also, custom Javascript code, that will hide the taxonomy dropdown and generate two dependent dropdowns for the states and cities. Then, it can synchronize the user-selected values to the hidden taxonomy dropdown. I mean, that it will select both the state and the city in the hidden dropdown.

Views might be used too, but they will need custom Javascript code to refresh them based on the user-selected values.

4) Maybe the Select2 library can help here. But, again, maybe it is not the best solution.

5) Many taxonomies, and many custom fields, can all be used simultaneously for filtering. By default, Toolset will apply an "AND" operator on them.

6) I am not familiar with the "Permalinks Pro" plugin. Maybe it can work smoothly for first page loads, but for pagination and searches, it may need customization for integration. And it may also just not work.

From our side, we try to be compatible as much as possible with 3rd party components(themes/plugins) and we give priority to the popular ones and those used by our users. If you use the plugin and encounter issues with Toolset, please open a ticket here and we'll do our best to help.

This being said, I'd also give some suggestions, hopefully, they would be interesting for you:
- Toolset has an integration with the Relevanssi plugin. You may use it to search for parts(zip code, city, state) from the address field. I don't think that it can index and address field, but we can work around it by duplicating the full address from the address field to a single-line field. https://toolset.com/course-lesson/searching-texts-in-custom-fields-with-toolset-and-relevanssi/
- Produce custom Javascript code, that will listen for the Address field, inside the Toolset form, and update some hidden(city, state) inputs. Then, you can save the city and state on a custom taxonomy, or on custom fields. IMHO, that would be the most cost-efficient custom code solution.

#2076329

Don

My issue is resolved now. Thank you for all the patient and informative help!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.