Skip Navigation

[Resolved] Related Posts by Distance

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 27 replies, has 3 voices.

Last updated by Timothy 1 year, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2516033

Hi,

I have a related posts view showing related Places using the View taxonomy filter, this is working fine. I'd like to also have one that uses the taxonomy filer but also filters based on distance. I have the addresses and coordinates for each Place and I see the Distance filter but this seems to filter by Places within a certain distance, not exactly the closest, right? Is there anyway to show the 3 closest Places?

Tim

#2516681

Hello,

In your case, you can order the result by distance ASC, and display 3 items only.
And the sortby distance option is available within Views in legacy editor.

You can follow our document to enable legacy view editor:
https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/

#2516683

Yes, I am using legacy views. But I'm not seeing this "sortby distance option". Are you referring to the Query Filter? If so I'm not sure how to configure this correctly to work for my needs.

hidden link

Tim

#2516705
sortby-distance.jpg

It is in section "Ordering", choose the custom address field-> As a distance from, see my screenshot sortby-distance.jpg

See below test site:
Login URL:
hidden link

post view:
hidden link

#2516791

Thanks, I think we're close. But I don't want "as a distance from" the visitor's location, it should be the closest from that particular Places/cpt location. So I tried to Url Parameter option and a view like this:

[wpv-view name="related-listings-by-distance-closest" placeAddress=[types field='location-address'][/types] ]

But that is displaying the same 3 Places for all posts:

hidden link
hidden link

Tim

#2516817

oh, that's a Url parameter setting, I thought it was a shortcode attribute... hmmmm. I tried the "Fixed Location" option with [types field='location-address'][/types] and wpcf-location-address but that doesn't seem to work.

#2516825

This post is 4 years old, would this still the best solution?

https://toolset.com/forums/topic/sorting-views-by-distance-to-current-post-geolocation/

#2519205
map-center.jpg

You can try the option "Distance center is set using shortcode attribute", see my screenshot map-center.jpg

Then pass shortcode as Views shortcode attribute, for example:
[wpv-view name="related-posts-by-distance" mapcenter="[types field='location-address'][/types]"]

#2520081

That doesn't seem to work. Also the Distance query filter becomes non-savable after it's saved once. Maybe there's a bug here?

hidden link

Tim

#2522291

I have tried it in above test site, it works fine, you can see the post view here:
hidden link

And here is the result page:
hidden link

It is using shortcode:
[wpv-view name="related-posts-by-distance" mapcenter="[types field='test-addr'][/types]"]

Is there any missing steps? can you reproduce the same problem in above test site, thanks

#2522309

How do I log into the test site?

Will this find the "closest" locations or just any location within X kms? My goal it so to show the 3 closest.

Tim

#2522313

Sorry, I was able to access the test site's view. My view is set up exactly like that. It seems to just show 3 random Places though, not the 3 closest.

#2523585

So the problem only exists in your website? If it is, the problem is abnormal, please check these in your website:
1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to WordPress default theme 2022, deactivate all custom PHP/JS code snippets, and test again

3) Also check if there is any PHP/JS error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/

4) If the problem still persists, please provide database dump file(ZIP file) of your website, you can put the package files in your own google drive disk, share the link only, also point out the problem page URL and view URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#2523611

I'm using the latest version of the toolset plugins and I don't see any errors. But before we do the rest, are you sure the test site you created does indeed show the closest places and not just ones within X kms? I need the closest places so I just want to make sure the solution you provided does indeed do this.

I have also tried the solution in this post which also does not work but it does allow me to see the distance to the related places:
https://toolset.com/forums/topic/sorting-views-by-distance-to-current-post-geolocation/

Tim

#2523661

Yes, I am pretty sure it works fine in the test site.

You can test it in above test site, or reproduce the same problem. thanks