Skip Navigation

[Resolved] Sort by Distance

This support ticket is created 2 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 21 replies, has 2 voices.

Last updated by Luo Yang 2 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#2373823

Tell us what you are trying to do?
- I am using the block editor. I have a Toolset search function set up with Toolset Maps and a Toolset Views output. People are able to search by location (eg. 50km of Sydney, Australia) and the markers show up on the map fine and everything works. But I want to be able to sort the results (in the Toolset Views output section) by distance.
- So if they search for "50km of Sydney, Australia", I want the search results below to show the ones listed as "Sydney" at the top (0km from their search), then the posts with "Chatswood" as their location (10km away from their search), then Paramatta (25km from their search of "Sydney"), etc.

I want the search results to show the closest suburbs at the top and the furthest suburbs at the bottom. (Currently all I know how to do is sort the suburbs in alphabetical order - ie. "Chatswood, Paramatta, Sydney")

Ultimately I want it so my front-end customers (the ones doing the search) will see their most relevant results at the top by default.

Is there any documentation that you are following?
- I've looked up several other support tickets but either they're not relevant to me, the solution isn't really clear, or they're too old and obsolete, now.

Is there a similar example that we can see?
- Probably.

What is the link to your site?
- offendersexposed.com.au

(Also, I have a second, lesser, still-related query: Can I make search results show randomly when there's no search parameters input by a customer? As in, they load my blank search page and it shows 20 random results out of the 2400 we have, but when they narrow down their search by typing something in; THEN it loses its 'randomness' and sorts by distance)

Cheers.

#2373941

Hello,

It is a known issue, see our erratum here:
https://toolset.com/errata/cannot-order-results-by-distance-in-views-created-with-the-block-editor/

You can try the workaround mentioned in above erratum, please let me know if you need more assistance for it.

#2374269

Hey Luo,

Thank you for this. I've now got the snippet on my website; what happens from here?

Is this code supposed to sort by distance by default? (Because it's not; at least not on the front-end)
Is this code supposed to make "Sort By: Distance" a selectable option on either the front-end or back-end, now? (Also not)
Am I supposed to remove all other sorting options and then it will work as the only option?

What happens from here?

There isn't much clarity on this.

Cheers,
Brendon.

#2374317

It should be able to work in frontend, and sort the result by distance, please share your website credentials in below private message box, and also point out
- the problem page URL
- where I can edit your custom PHP codes

#2378207

How are we looking on this? Has any progress been made?

#2378589

Thanks for the details, I am checking it in your website, will update here if find anything

#2378697

Hey, thank you.

You were logged in for quite a bit today and made a few changes, I saw.

What's the prognosis?
Did I make a mistake with adding your workaround?

Cheers,
Brendon.

#2378713

I can see the problem in your website, there is nothing wrong in your custom codes, it is simply not working as expected.

Since your website is a live production website, I don't want to break it while doing debug, please provide a copy of your website in below private message box,
https://toolset.com/faq/provide-supporters-copy-site/
I need to test and debug it in my localhost.

#2379127

Okay, thank you.

It seems my website is too large for the free version of Duplicator (twice the size, in fact) is there another way that you guys are happy to use? Or do I have to pay the $70 to upgrade to the pro version?

Cheers,
Brendon.

#2379331

You can follow Duplicator document to export the database only package file:
hidden link
Then put it into your own Google drive disk, share the link in below private message box, thanks

#2379419

The file "installer.php" is missing in your shared link, please share it too.

#2379423

Please double-check; I can assure you it's there.

#2379447

I can find it, trying to duplicate the same problem and debug it in my localhost, will update here if find anything

#2379455

Thank you.

Please let me know how you go.

And thank you for your help. I really appreciate it.

#2380143
orderby-distance3.JPG

The custom codes does not work for view block any more, please try to setup the view with legacy editor, and order the result by address distance, see my screenshot orderby-distance3.JPG

It works fine with your duplicator package in my localhost, please let me know if you need assistance to setup a demo in your website.

More help:
https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/