Skip Navigation

[Resolved] Distance filter

This support ticket is created 4 years, 6 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 2 replies, has 2 voices.

Last updated by allisonM-2 4 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1863813

Tell us what you are trying to do?
I am trying to generate a list a posts that are within x distance from the item being shown. For example, I have a custom post and template for a hotel that has an address. I want to show all restaurants within a certain distance from the hotel on the template. I cannot seem to get the filter to use the hotel address as the comparison address for the distance filter. I am pretty sure you would be able to do this I am just not sure how. I would also love some guidelines/examples for what goes into the fields "Distance (center, radius, unit) URL parameter to use" on the distance filter.

Thank you!

#1864183
distance-filter.JPG

Hello,

You can use Types shortcode to get current post address field value, for example:
[types field='my-address' item='$current_page'][/types]
https://toolset.com/documentation/customizing-sites-using-php/functions/#address
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

And pass above value as Views shortcode attribute, see my screenshot: distance-filter.JPG
Show posts within XXkm radius of address/coordinates provided using mapcenter shortcode attribute.

Here is the document for "Filtering and Ordering Map Markers by Distance in WordPress"
https://toolset.com/course-lesson/filtering-and-ordering-map-markers-by-distance/
For your reference.

#1871861
distance block.PNG

Thank you for your response. My distance block looks different than the one you sent a picture of - do I need to update? Looks like I have the latest.

I tried putting 'mapcenter' into the field but nothing worked. Where do I type in the shortcodes? I haven't been able to find where those go.

Thank you!