Skip Navigation

[Resolved] Distance Radius Search: if no results – show nearest result

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by simonC-7 1 year, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2579947

Tell us what you are trying to do?
When some searches are done there are, of course, some times when there are no results found - example:
20 miles, Hull UK, Personal Policy, Health Insurance

When there are no results, I would like to show the NEAREST company who match the search (other than the distance radius), with the message: "There are no results in the area you specified. Your nearest company is" and then display that result.

What is the link to your site?
hidden link

#2581095

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

There is no such AI feature available that system will automatically query nearest location.

The only possibility is you can display a fixed location when there is no results found as Views works on the supplied search arguments and simply if it will find the result it will display it and if not, there is nothing to display.

There is no automatic way to fire another query and system do not know what is the nearest location.

#2581307

Hi Minesh,

When the query is created the system is told:
Users location, users choice of distance radius, and the search criteria
Surely we can return an array of all results and then
a) loop through and list all results that are < the distance selected
b) if there are no results within the distance - show the first lowest distance result

Is that possible?

#2581317

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

That is what I'm saying that there is no automatic way to do so.

How to tell system that with what range you should display the result within how many km/miles. If there is result it will display the result within the specified address, if there is no result there is no way to run another query. This could be achieved but then it needs extensive custom programming and such custom work is beyond the scope of our support policy.

If you need such custom programming for your project, you're welcome to contact any of our certified partners:
- https://toolset.com/contractors/

#2581321

Thanks. I don't see the need to run another query if the initial query returns ALL results at ANY distance. Then loops through the results to see if there are any results within the distance, if not it returns the first (nearest) result in the returned query.

#2581329

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Toolset view does not work like that way you think.

As shared, whatever address you passed to view, if the results found within the range (with applicable filters user added to his search) it will display the results otherwise not.

I already shown you how you can customize the results with the Toolset views hook "wpv_filter_query_post_process".

You can customize your output as per your requirement by adding your business logic there.

#2581361

Thank you, I will seek assistance using the hook.