Skip Navigation

[Resolved] Show posts close to the current one

This thread is resolved. Here is a description of the problem and solution.

Problem: I am displaying a View of locations and I would like to add a distance filter. The distance should be calculated from a custom field in the current post.

Solution:
Turn caching off and place the custom field in the mapcenter attribute using output='raw'.

[wpv-view name="Locations in der Nähe" mapcenter="[types field='traulokal-adresse' output='raw'][/types]" cached="off"]

Relevant Documentation:
https://toolset.com/documentation/user-guides/display-on-google-maps/filtering-and-ordering-map-markers-by-distance/

This support ticket is created 6 years 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by marcialB 5 years, 12 months ago.

Assisted by: Christian Cox.

Author
Posts
#1161372

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

#1162417

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.

#1165377

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

id='$current_page'

, right?

If this seems correct to you, maybe you could have a look at it.

Thanks

#1165611

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.

#1167933

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

#1168450

Thanks, Christian!

It now works. I also reduced the radius to a lower value to confirm.

Best,
Marcial