Skip Navigation

[Resolved] I need help making a conditional map query

This thread is resolved. Here is a description of the problem and solution.

Problem:

I have a map and a search query on a page where the distance is hard-coded to 50 miles. If no results are found within 50 miles, I want to automatically expand the search to 350 miles without requiring the user to re-enter their address. I considered using the [wpv-no-items-found] section to trigger a second view but wasn't sure how to pass the user's address to the second view.

Solution:

You can pass the URL parameter containing the user's address from the first view to the second view. Use the URL parameter toolset_maps_distance_center to set the address in the second view, which will then perform the expanded search within 350 miles.

Relevant Documentation:

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.

This topic contains 3 replies, has 3 voices.

Last updated by Christopher Amirian 4 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2727345

Currently I have a map and a query on this page: hidden link

At the request of the client, I've hidden the distance selector and distance has been hard coded to 50 miles.

What I'd like to do is if no results are found within 50 miles change the search to 350 miles and resubmit/show output.

Is there a way to do this with the [wpv-no-items-found] section of the loop editor?

I was thinking I can write a separate view exactly like the first but hard code it to 350 miles and then have that view output show in the [wpv-no-items-found] section, but I'm not sure how to pass the user address from one view to the other without making them re-enter it. Can this be done?

#2728238

Nigel
Supporter

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

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

So the page loads and it shows the search filter where a user enters an address.

On the initial page load the map will show all results because an address has not been provided.

The page reloads when the address is submitted, and the map shows the matching results (within 50 miles).

If there are no results, the [wpv-no-items-found] section will be displayed, and the intention is to include another View, this time with a distance query filter set at 350 miles.

Well, after the user enters an address the first time and the page reloads, there will be a url parameter with the address, and that will be accessible to the second View.

So set the address based on the same address url parameter generated by the first View.

I think that might work.

#2728543

Hi Nigel - the part I'm missing is how do I access the URL Parameter with the address from the second view (specifically)?

#2729665

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Here is how to pass a URL parameter to a view:

https://toolset.com/documentation/legacy-features/views-plugin/passing-arguments-to-views/

For your scenario the URL parameter that you need to pass to the second view is:

toolset_maps_distance_center

Thanks.

#2735950

Perfect - thanks for your help!