Skip Navigation

[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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Ce sujet contient 15 réponses, a 2 voix.

Dernière mise à jour par prasadS Il y a 4 années et 7 mois.

Assisté par: Shane.

Auteur
Publications
#1572467
Screenshot 2020-04-02 at 9.25.00 PM.png
Screenshot 2020-04-02 at 9.27.52 PM.png

Tell us what you are trying to do?

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.

Is there a similar example that we can see?
No.

What is the link to your site?
lien caché

#1572653

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Prasad,

Thank you for getting in touch.

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"

Thanks,
Shane

#1572907

Hey, Shane!
Thank you for the reply.

I do not wish to use the visitor location and show posts (attractions) near the user.

On each attraction, I wish to display attractions around it (say around 2 km range).

Please let me know if I have explained correctly or if you require moe details.

#1573309

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Prasad,

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.

Without a center point this filter wont work.

Please let me know if this clears it up for you.

Thanks,
Shane

#1574333

Hi Shane,

I do not wish to enter a particular fixed location as the center.

I want the center to be set as the current post being viewed.

And the view should display posts within 2 km from the current post.

Below is the shortcode I am using to display the view.

[wpv-view name="nearby-attractions-displayed-on-attraction" mapcenter="[types field='attraction-address-map']

Kindly help.

#1575721

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Prasad,

Thank you for the clarity.

If you have not already done so then you will need to select the filter to "distance center is set using shortcode attribute".

This will cause your code to work with

[wpv-view name="nearby-attractions-displayed-on-attraction" mapcenter="[types field='attraction-address-map']

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.

Thanks,
Shane

#1575753
Screenshot 2020-04-06 at 8.06.15 PM.png

Hi Shane,

Yes. I have already selected the filter to "distance center is set using shortcode attribute".

Please check the screenshot of the options I have selected.

I am creating a staging website for you to check and test this. Will send login details in my next reply.

#1575801

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Prasad,

I've enabled the private fields for your next response so that you can provide the credentials as soon as possible.

Thanks,
Shane

#1576137

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Screenshot 2020-04-06 at 2.36.53 PM.png

Hi Prasad,

Thanks for the staging site. I was able to debug the issue and have a solution.

If you add your shortcode to a Test Editor it would work fine, see Screenshot.

This should allow your filters to work properly now. The shortcode widget doesn't seems to be able to handle nesting of shortcode.

Please let me know if this helps.
Thanks,
Shane

#1576297
Screenshot 2020-04-07 at 3.42.15 AM.png
Screenshot 2020-04-07 at 3.40.34 AM.png

Hi Shane,

For some reason it is still not working for me.

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.

Kindly help.

#1577233

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Prasad,

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.

Right now this is an example of what you have


[wpv-view name='my-view' param="[types='my-field'][/types]

Where the Closing tag and closing quotation is missing.

What you should have is


[wpv-view name='my-view' param="[types='my-field'][/types]"]

Notice at the end I've added the closing quotations and the tag.

Please let me know if this helps as it works when I tested it.

Thanks,
Shane

#1577875

Hey, Shane!

This worked perfect! Thanks a lot for the help.

I need help with 2 more things related to this.

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.

[wpv-view name="nearby-attractions-displayed-on-attraction" mapcenter="[types field='attraction-address-map'][/types]"]

2) Is it possible to order the posts in the view to show the nearest post first (ascending order in terns of distance)

#1577887

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Prasad,

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?

You should be able to do it with the shortcode below.


[toolset-maps-distance-value origin_source='[wpv-attribute name="mapcenter"]'  unit='KM']

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.

Please let me know if this helps.
Thanks,
Shane

#1578283
Screenshot 2020-04-08 at 1.56.05 PM.png

Hi Shane,

Thank you for the answers.

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 checked this link: https://toolset.com/documentation/user-guides/maps/maps-shortcodes/#toolset-maps-distance-value
and I tried to add more arguments inside the shortcode but it did not work for me.

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.

#1578663

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Prasad,

To do this you will need to use this exact shortcode in your view.

[toolset-maps-distance-value location='[wpv-attribute name="mapcenter"]' postmeta="wpcf-attraction-address-map"  unit='KM']

Please let me know if it works for you as it works fine on the staging site.

Thanks,
Shane