[Résolu] Display Posts In a View Based on Address Field and Current Post
This support ticket is created Il y a 4 années et 7 mois. 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.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
I have a custom post type names 'Attractions'. There is an address field in it with slug "attraction-address-map".
I want to create a view to display nearby attractions on each Attraction.
The view that i have created, shows all attractions (Please see attached screenshot and this link: lien caché). I want to show nearby attractions in a range of say 2 km only.
Can you tell me the options to select in the Ordering and Query Filter? (Please see screenshot attached for my existing view)
Is there any documentation that you are following?
No.
For clarity you mentioned this "I want to show nearby attractions in a range of say 2 km only." Will this be 2km from the user who is viewing the view location ?
If so then you just need to select the option that says "distance center is set from user location".
For the Order settings you should set it as "A distance from " -> "Visitor Location"
I understand what you are trying to achieve but there needs to be a center point.
Perhaps what you need to do is to set a distance filter center point in the filter. If you have a look at your screenshot you will see that that there is an address field that you can use to set what the center point is.
From there once you set that center point then the view will filter for all the posts that are within 2km of that center point.
If you've already set the filter to this and you're still having issues please let me know. Also please provide admin access so that I can check the view as well.
The single post template for 'Attractions' custom post type is created using elementor. Elementor template name is 'Template for Attractions'.
I added the shortcode using a text editor. It is still not working for me. The view is returning all posts, instead of posts only within 2 km as set by the view.
I have attached a screenshot of my currently view settings.
I have also attached a screenshot of the single post template for attractions.
You screenshot has highlighted the issue. If you take a look at the WYSIWYG editor you will notice that the views shortcode is missing the closing tag.
1)In this view, how can I show the distance between the current post and each post shown in the view. Could you please guide me with that?
If possible can you help me with what I must add to the shortcode below for the same. Or If I should be using another shortcode.
2) Is it possible to order the posts in the view to show the nearest post first (ascending order in terns of distance)
Actually no based on your current setup. If you were using a frontend search parameter then it would be possible, but the order option is not able to get the center location from a shortcode parameter.
I added the toolset-maps-distance-value shortcode you shared inside the view content. But I am not able to see the distances in the view. Could you please help me with the additional info that I many have to add to the shortcode?
I want to calculate the distance between the current post and the post / posts shown in the view and display it inside the view.
The custom field slug for the map address field is wpcf-attraction-address-map
Please let me know if you require more information from my side.