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
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/
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
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
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
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.
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]"]
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
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
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
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.
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/
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
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