Skip Navigation

[Resolved] Passing a Variable to a nested View

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.

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-map-marker
https://toolset.com/documentation/legacy-features/views-plugin/passing-arguments-to-views/

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 9 replies, has 3 voices.

Last updated by Mateus Getulio 2 months ago.

Assisted by: Mateus Getulio.

Author
Posts
#2743278
map-query-filter.jpg

This is a continuation of this ticket: https://toolset.com/forums/topic/i-need-help-making-a-conditional-map-query/

I also read the instruction on this page: https://toolset.com/documentation/legacy-features/views-plugin/passing-arguments-to-views/

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?

#2743392

Nigel
Supporter

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

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

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.

#2743782

Hi Nigel - that's correct.

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!

#2744532

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi there,

This is a brief note to let you know I'll create an example and share with you as soon as possible.

Thank you,
Mateus

#2745022

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

Please check this example:

hidden link

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?

#2747285

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?

Thanks for your help!

#2747344

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi,

To suggest the best way to achieve this, I'll need to see how this view is set up in the admin area.

Can you please share temporary admin login details along with a link to a page where this view can be seen?

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Mateus

#2748795

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

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

I kept this structure unchanged, but I transferred the markers(popup + icons) from the map block directly into the content template using a shortcode block and the [wpv-map-marker]: https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-map-marker

I also added the markers to the '350 miles search range' view.

By doing that, now the markers are 'rebuild' when the secondary view with the 350 miles range is called.

Can you please test it and confirm it is working as expected?

Thank you,
Mateus

#2749490

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!

Thanks again.

#2750065

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello Claudia,

Thank you for confirming the solution worked.

Absolutely, I'll add your case to the request to increase the priority and to be able to let you know once we have news regarding its development.

Thank you,
Mateus