Skip Navigation

[Resolved] Distance search (and sort) on repeating address field

This support ticket is created 6 years, 2 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 6 years, 2 months ago.

Assisted by: Nigel.

Author
Posts
#1109649

Tell us what you are trying to do?
I have partners that have multiple locations via a repeating field for address. I need to be able to sort and search these partners on any and all addresses related to their custom post type but it seems like Toolset Views and Maps only search on one address occurence from the repeating group.

If I create a partner with locations in Boston, MA and Hartford, CT, I can only search for them by location using the first of the addresses.

Is there any documentation that you are following?
Maps documentation doesn't get this detailed.

Is there a similar example that we can see?
Not that I know of. Other threads asked how to show more than one address on a map but didn't mention searching and ordering at all.

What is the link to your site?
This is not on the site yet. Our existing partner search is custom PHP code that I am trying to replace.
You can go to hidden link
and you'll see two partners, the first has two locations listed and the second has one location listed. Partners are separated by an HR. If you search on Littleton, MA you'll see both partners and all addresses. If you search for Hartford, CT, you won't get any results.

In the database, the Littleton location comes before the Hartford location in the _wpcf-partner-address-sort-order postmeta for the partner with the two locations. Even switching the order here doesn't change anything. Toolset only uses the first address that occurs in postmeta for the search. If I delete the Littleton location, the Hartford search works. If I add the Littleton location back, making it the second in the database, only Hartford search finds this partner. If I then delete Hartford and re-add it, Littleton becomes first and Littleton search now works again but Hartford does not.

Clearly there is no support for repeating addresses in the distance search. Is this as intended and not going to change anytime soon? In other words, do I have to separate locations into their own post type as a child of partners to be able to search for partners with more than one location or is this going to be fixed so I can use a repeating address field for partners with more than one location?

#1110324

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Scott

Thinking through this in the context of the underlying WP_Query I can see the problem in terms of implementation.

You are searching posts based upon its distance to x, but if a post has multiple addresses, what is the distance?

Well, to answer my own question, if you are performing a radius-based search, then the distance should be the lowest of the distances for each address.

It isn't currently supported. I just chatted briefly with the Maps developer who says it wasn't a use-case they had anticipated, but it should be possible to implement, so I'm raising a feature request ticket for this.

The alternative—adding addresses via repeatable field groups or child posts—doesn't really help right now, because filtering based upon fields of a related post is not yet supported, it is one of the main things being worked on in the upcoming Views dev cycle.

I'm not sure how long it will take to implement, but it's agreed to update maps for this case.

#1110520

In our current implementation we use locations as repeatable field groups and have built our search with PHP to have two behaviors. One that searches the parent by taxonomy or text and another that searches locations by service area radius (customer enters zipcode of a potential project and we show partners whose service area radius includes the center of the project zipcode). Because so many customers are used to the traditional store locator type of search (proximity between target address and business addresses), we're switching to that model but we need to deal with some of the business partners having more than one location and we don't want to enter all their info and taxonomy for each location so we'd like to stick with an approach that has a repeatable field group for partner location.

I may have to modify my existing PHP based search for now but it'd be great if Toolset gained this ability in the future.

I have another ticket open regarding converting our data that is in separate street, city, state, zipcode (and lat / lng) fields to Toolset Address fields. It seems like now is the time to make this conversion regardless of whether we can use Maps / Toolset for the search as it'll make us more ready for future Toolset capabilities. But I have two questions: one, can I easily use a MySQL query to add wpcf-partner-address postmeta fields and can I access the lat / lng that gets cached for each of these fields easily to use in my search code?

#1111509

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Scott

We have a Maps update due very soon (it is currently in QA testing), and the issue of filtering posts with multiple addresses by distance to be based upon all of the addresses will be addressed in the next minor point release, so we are probably looking at a timescale of weeks.

Your reply mentions using repeatable field groups rather than repeating fields, which is a different issue, and would be facilitated by the next major Views update which should add the ability to filter by fields of related posts (or repeatable field groups).

Regarding your last point, the address stored as post meta is the formatted string of an address returned by the Google API. The coordinates for that address are cached in wp_options with an option named toolset_maps_address_coordinates. You can use standard WP functions to retrieve and set the options, it would be best to inspect the database where you will see that the option is stored as a serialised array, and you can use a tool such as hidden link to get a better idea of what's included. The WP functions such as update_option and get_option handle the serialisation automatically.