Skip Navigation

[Resolved] Can I order results by distance only when the distance filter is used

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 1 reply, has 2 voices.

Last updated by Nigel 8 months, 3 weeks ago.

Assisted by: Nigel.

Author
Posts
#2690873

Hi there

I am trying to work out whether the following scenario is possible.

I have a directory with a number of options for searching and filtering: hidden link

Currently the directory entries are always displayed alphabetically by first name.

If it possible that when people use the distance filter, the results are displayed ordered by distance from the location in the filter (nearest first)? (But when the distance filter it not used they continue to be ordered alphabetically.)

Thanks
Lucy

#2690920

Nigel
Supporter

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

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

Hi Lucy

It isn't possible to set up this up in the UI, but you can add a little code that uses the Views API to modify the View settings programmatically to achieve the same.

See this erratum: https://toolset.com/errata/cannot-order-results-by-distance-in-views-created-with-the-block-editor/

You need to edit the ID of the View it should apply to, as well as the slug of the address field.

Let me know if you have any problems.

#2691509

Thank you for this. I won't be able to implement it for another couple of weeks but will get back to you if I have any problems when I do.