This thread is resolved. Here is a description of the problem and solution.
Problem:
The customer was trying to create a search functionality on their website that displayed locations based on a user's input. They had built a view that showed locations within 50 miles of the user and created a nested view to display results within 350 miles if no results were found within the initial range. However, the nested view did not trigger correctly based on the user’s input, leading to issues in displaying the appropriate results.
Solution:
We confirmed the customer's setup and created a working example to demonstrate how to achieve the desired functionality. We provided guidance on setting up the main view and the nested view using the URL parameter toolset_maps_distance_center for filtering. We also suggested moving the map markers from the block directly into the content template to ensure that the markers would rebuild when the nested view was called.
Although the customer inquired about displaying the distance from each result to the user's location, we noted that this feature was under consideration for future versions of Toolset. However, a straightforward solution was not readily available.
After implementing the changes we suggested, the customer confirmed that the nested view was functioning as expected, effectively displaying the relevant markers on the map.
I've built a view that displays a list of addresses. I've set the initial view to show locations within 50 miles of the user. Distance is hardcoded and hidden. If no locations are found, I created a nested view to show locations within 350 miles of the user. In the nested view I'm using a Query Filter that uses the URL parameter toolset_maps_distance_center (see image).
The page is here: hidden link
I know that the nested view is pulling through because it triggers the wpv-no-items-found of the nested view when you search using a location that's more than 50 miles away - but it doesn't trigger the 350 mile search.
Am I doing something wrong, or does toolset not support this?
Let's see if I understand this (I'm essentially repeating what I wrote in the previous ticket).
Users arrive at this map page.
On the initial visit, no location is provided, so the page returns all results irrespective of difference.
The user submits their location. The radius is hidden, and fixed at 50 miles.
The View is updated to show the results within that radius. If there are no results another View is output. This one should take the location provided by the user and expand to show results within 350 miles.
Is that correct?
The distance filter of your outer View uses the URL parameter toolset_maps_distance_center? In which case I would expect you to be able to add a Query Filter in the second View that depends on the same URL parameter.
And that doesn't work?
If you can confirm that I've understood your workflow correctly and it doesn't work I can try something similar to see if I can spot the problem.
One aspect I'm unsure about is the Search and Pagination field of the nested view (350 Nested Location Search). I've set it up similarly to the outer view, just with the 350 Miles distance filter, but as the nested view is set to only show output the user never interacts with the search field. Is that possibly causing the issue?
I hope you can make it work on your end. This would be very useful if so. Thanks!
Try to search for Antwerp, Belgium. That's within 50 miles of Brussels, so that should show up in the results.
Now try entering Amsterdam. There are no results within 50 miles, so it shows the results within 350 miles.
You can use this login link to check how the views are set up: hidden link
In summary, we have two views, one named 'Places within 50 miles' that is the original view rendered, and with the wpv-no-items-found shortcode we render 'Places within 350 miles'. The latter will get the parameter 'toolset_maps_distance_center' defined in the URL and pass it to the filter section:
Show posts within 350mi radius of address/coordinates provided using toolset_maps_distance_center URL parameter.
Can you please give it a try on the live and let me know the results?
Hi Mateus - I was able to get the nested map to work similar to the example you created, however in your example you used map markers right in the views whereas I have to display what is often the multiple results of a view.
How do I get the nested view results to show up on the original map? Or do I have to create a second map and make the maps themselves conditional? And If I do that, how do i get the results of the nested view to show up on that map?
Also - separate question, but relevant. Is there an easy way to conditionally display the distance from the results location to the user entered location? So say there are 3 results, and one is 58 miles, one is 89 miles, and one is 205 miles. How would I display that distance conditionally in the result?
Regarding showing the distance from the user location/search center and each item in the loop, I searched for it and found that there's an open feature request to include this in upcoming versions. Although I'm afraid I can't give you an exact ETA for when this feature will be included. I looked for a workaround that wouldn't involve too much custom code but I couldn't find something straight forward.
With regard to the search issue, I checked it with our team and what needed to be done was to move the markers from the block directly into the template within the view.
The structure you have at the moment looks like this:
1- A page that has a map block using a view for the data and setting the markers within the block itself
2- A view for the location
3- A content template for the design of the loop items
Hi Mateus - Yes this is working as expected now, thank you! I see you put the map marker in the content template as a shortcode. Perfect. Thanks for your help!
Also, please add me as a vote to get the distance from user location/search center to each item in the loop added as a feature. That would be helpful!