Hi there
We have a CPT for locations. Within each location, we would like to display locations that are close to the one the user is currently looking at.
In the filter settings of a view (that I want to place in the post layout), I have the option to filter posts by distance. Is there an option to use the address of the current one to compare with the address of the filtered locations? It automatically choses our address field, but as far as I understand, that only uses the address of the post to display and not the current one. Can I somehow get the current address in the shortcode maybe, so I can use the shortcode parameter predefined as "mapcenter"?
Best,
Marcial
Hi, yes you can use a shortcode parameter "mapcenter" to set the distance filter origin. To place the address of the current post in this shortcode attribute, you can use the wpv-post-field shortcode and the $current_page operator:
[wpv-view name="your-view-name" mapcenter="[wpv-post-field name='address-field-slug' id='$current_page']"]
If that doesn't work as expected, let me know and I can take a closer look.
Hi Christian
It keeps displaying random posts ignoring the radius I defined. Based on your example, I replaced the view-name and the slug of our address field.
I don't have to adjust the
, right?
If this seems correct to you, maybe you could have a look at it.
Thanks
Please provide login credentials here and I can take a closer look. Let me know where I can find the View on the front-end of your site.
It keeps displaying random posts ignoring the radius I defined.
I turned off caching and placed the address field using the raw output:
[wpv-view name="Locations in der Nähe" mapcenter="[types field='traulokal-adresse' output='raw'][/types]" cached="off"]
It seems to be working as expected for me, can you confirm? I tested Schloss A Pro many times, and used Google Maps measurement tools to test the distances. These were the results:
/restaurant-tisch-und-bar/ 34km
/grandhotel-giessbach-am-brienzersee/ 46km
/rathaus-korporation-ursern/ 28km
/schloss-heidegg/ 45km
/restaurant-milchsuedi/ 36km
/haus-am-see/ 28km
/schloss-schauensee/ 30km
/freulerpalast-naefels/ 42km
/schwesternhaus/ 37km
/kneipp-pavillion/ 32km
/ryserlaeuferhuus-schwanden/ 37km
/brauiturm-hochdorf/ 40km
/sankturbanhof-aebtesaal/ 50km
/portraitsaal-luzern/ 30km
/altes-schulhaus-luchsingen/ 33km
/kommende-hohenrain/ 40km
/schloss-rapperswil/ 41km
/c-f-meyer-haus/ 49km
/custorhaus-eschenbach/ 46km
/villa-vilette/ 35km
Remember, the distance measurement is not the same as the driving distance. Distance is measured in a straight line between points. Driving distance is usually farther.
https://support.google.com/maps/answer/1628031?co=GENIE.Platform%3DDesktop&hl=en
Thanks, Christian!
It now works. I also reduced the radius to a lower value to confirm.
Best,
Marcial