I'm trying to set to set up a view that displays addresses within a search radius. But I need to have the Addresses set as a repeatable field, and several of the results will only have one address within the results radius. But the map markers will display all of the address results, even if only one matches the radius. (see attached screenshot).
To solve this, I'm trying to create a conditional display, structured like this:
For each address > Find the distance from toolset_maps_distance_center > If distance is less than toolset_maps_distance_radius > Add map marker.
Does this need a custom function to work? Or can I only display the addresses within the search radius using the loop builder?
I have all the pieces in place, but my formatting must be wrong because this version does not return any results:
<wpv-loop>
[wpv-for-each field="wpcf-address"]
[wpv-conditional if="( $([toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-address' unit='mi']) lt [wpv-search-term param='toolset_maps_distance_radius'] )" debug="true"]
[toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-address' unit='mi'] [wpv-post-body view_template="full-name"][wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_field='wpcf-address'][wpv-post-body view_template="full-name"][/wpv-map-marker]
[/wpv-conditional]
[/wpv-for-each]
</wpv-loop>
Thank you for your attention to this matter.
Hi,
Welcome to Toolset support.
[wpv-for-each field="wpcf-address"] loops over each stored address value, but the map/distance shortcodes you’re using still “look” at the whole field on the post, not the current item in the loop. That’s why your conditional returns nothing (or you end up placing markers for all addresses anyway).
Suggestion: Move addresses into an RFG and filter the RFG items by distance.
- Create a Repeatable Field Group “Addresses” with a single Address field inside.
- (Re)enter addresses so each address is an RFG row.
- Add a View whose Content Selection is “Repeatable field groups from the current post → Addresses”.
- In that View, add a Distance filter for the Address field, set the source to the front-end distance controls (the same controls you already have; they set toolset_maps_distance_center and toolset_maps_distance_radius).
- In the View Loop, output one marker per matched row. For shortcodes this looks like:
[wpv-map-marker map_id="map-1" marker_field="wpcf-address"]
Only the RFG rows within the radius are returned, so only those markers are added.
- Render your map once (above), for example:
[wpv-map-render map_id="map-1" cluster="on"][/wpv-map-render]
…and insert the RFG View below it so the markers land on that map.
Thanks.
I appreciate the suggestion to use a RPG. But that is adding an enormous amount of complexity in terms of migrating data, establishing relationships, and and rebuilding forms.
Plus it wouldn't be a very user friendly experience to ask our members to enter new addresses (one at a time) in a separate form from the rest of their profile info.
Tldr: I would rather display extra markers than spend a dozen hours to generate a worse UX.
Are there other options? Like, what if I used a content template inside the for-each so that it evaluates the address individually?
Hi,
Unfortunately, I can not think of any other way to have what you want.
I wish I could give you something but alas I do not think so.
Thanks.