Skip Navigation

[Resolved] Order View by Distance

This support ticket is created 2 years, 9 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by umbertoZ 2 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#2295347

Hi, I want to build a view with a map, serch filter by distance and then I want to display the result ordered by distance (the closest location first).

Is this possible?

I read this thread:
https://toolset.com/forums/topic/displaying-and-order-by-distance/
and this doc:
https://toolset.com/course-lesson/filtering-and-ordering-map-markers-by-distance/

But it is not clear. I don't understand if the view is supposed to order it by distance by default or not.

I built a test view and it doesn't seem to order the locations correctly.

Can you help me?

cheers

#2295619

Nigel
Supporter

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

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

It should work, and mostly does, though we have had a couple of clients reporting that it doesn't.

In those cases we've narrowed the problem down to the SQL query that calculates the distance returning null (instead of the distance), but haven't determined precisely what circumstances are required for it to fail.

Can I get access to your site to be able to see if the same is happening in your case? If so it will give us a little more ammo to throw at the problem.

Let me mark your next reply as private so that we can get log-in credentials from you—you may want to create a temporary admin user for us to use that you can later delete. And be sure to have a current backup of your site.

Can you also confirm the url of where you have this set up?

#2296247

Nigel
Supporter

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

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

Screenshot 2022-02-18 at 07.39.00.png

Actually, I think the issue here is much more basic.

I hadn't noticed before now, but you cannot order the results by distance when using blocks to create the View, the option is only available in the legacy editor (screenshot).

And even in the legacy editor, the distance option is missing if you try to add front-end sorting controls.

The documentation you linked to ("Filtering and Ordering Map Markers by Distance in WordPress") makes no mention of how to order by distance.

I'm creating internal tickets to add the missing option to Blocks, and to update the documentation.

In the meantime you will have to create a View using the legacy editor to be able to order by distance.

(You can create the View in the legacy editor but still insert it into a blocks-based page with the View block, and add the map using the Map block, with the marker source set to the new legacy View.)

#2296357

My issue is resolved now. Thank you!