Home › Toolset Professional Support › [Resolved] Display grandparent fields in a map marker
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 |
---|---|---|---|---|---|---|
- | 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)
This topic contains 18 replies, has 2 voices.
Last updated by Arno 2 years, 8 months ago.
Assisted by: Shane.
Hi,
I have 3 nested views:
A
B is a child of A
C is a child of B and has a geolocation field
I created a custom search view for users to find posts of type A. The map shows the locations from C. That all works fine.
Now what I need is the map markers to show fields from A. After reading https://toolset.com/forums/topic/nested-view-inside-view-of-related-posts/ I thought this might be possible. It looks like there used to be documentation at https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-fields-of-grandparents/, but it now redirects to a page about relationships but only parent-child, not grandparent/grandchild.
How to I address the fields of A while looping through the posts of C?
Hi Arno,
Thank you for getting in touch.
Essentially you're listing out the grandchild and want to get the grandparent. This might be a little tricky to achieve but should still be possible to do.
Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?
Please where applicable please provide me with a link to an example page where I can see the issue.
I've enabled the private fields for your next response.
Thanks,
Shane
Hi Arno,
I managed to do this with another view that filters for the itinerary based on the Post relationship between Itinerary and town.
Here is the view that was created.
hidden link
I then added the post relationship filter and set it to filter the relationship based on the provided ID. I then pass the parent ID of this view below.
hidden link
Then using the shortcode [wpv-post-id item='@town-location-relation.parent'] to get the ID of Town, I pass this town ID into the view like this.
[wpv-view name="list-itinerary" wpvrelatedto="[wpv-post-id item='@town-location-relation.parent']"]
This is how I was able to get the information from the Itinerary Post Type.
Please review and let me know if the created view is displaying the correct information.
Thanks,
Shane
Hi Shane,
I'm impressed. Indeed I now have access to the grandparent fields from within the town location, the child. Thanks.
Now there's one issue left: it's many-to-many relations. So one town can be related to multiple itineraries. That results in multiple markers per town. That's no problem if each marker would show data of one itinerary, but since the town ID is used to get the itinerary data, it will always return all itineraries. So all markers of one town show all itineraries. Duplicate markers!
It there a way to get unique data? I tried changing the marker ID from this...
marker_id='marker-[wpv-post-id]' (that's the location post id)
to this:
marker_id='marker-[wpv-post-id item="@town-location-relation.parent"]' (that's the town post id)
...hoping that it would only create one marker, but it automatically adds "-1" when a duplicate marker ID is used. So the result is the same.
Hi Arno,
Can you show me an example.
Given that its a many to many relationship it's going to be quite tricky to decipher which one you want to be added. One way to work around this is to restrict your view to only display 1 items only but can you provide an example so that I can understand a little better.
Thanks,
Shane
Hi Shane,
It's tricky, I agree. It hope it's not impossible, particularly with a no-coding solution.
The setup is:
Itinerary <> Town <> Location, all many-to-many relations. While iterating through the Locations, I can get the parent Town, but that Town can be related to more than one Itinerary. The problem is that we process each Location multiple times (for each Itinerary), and each is going to find the same parents.
I have a view to search Itineraries. I would like to have a map with either:
1. multiple Locations per Town, each Location marker showing one Itinerary
or:
2. one Location per Town, each Location marker showing all Itineraries the Town is related to
Option 2 would be more user friendly. They user could click on a marker and immediately see which Itineraries include that Town.
If it was somehow possible to get a collection of unique Locations based on the filtered Itineraries, then we'd have option 2 and the problem would be solved by your example. Or, if we could skip a map marker if the Location was already added to the map earlier in the loop, that would solve this too.
Thank you,
Arno
Hi Arno,
2. one Location per Town, each Location marker showing all Itineraries the Town is related to
We may be able to do this one because currently it appears that you have the spiderfy option enabled on your map. I wasn't able to disable this as your map block is now showing an error.
It would appear to me that the problem is being caused by some minifying of the Javascript.
Then in the itinerary we should be able to display multiple items within the marker details.
Please let me know and then we can take it a step at a time from there.
Thanks,
Shane
Hi Shane,
That's weird, I did not change anything related to maps, minification or the Litespeed plugin. I did notice that Litespeed was disabled today. Not by me, probably by your colleague. But all I did was enable it again. That should not cause this issue.
I purged all cache but that did not help. Then I disabled "JS Minify" and "JS Combine" in Litespeed and again purged the cache and reloaded the template with the view. The map block now worked again and I disabled the spiderfy option. But the issue was back quickly and it's affacting all maps blocks in all templates. I even tried disabling Litespeed, Wordfence and Toolset Access, but nothing helps so far.
This is the first error in the browser console:
Error 403 on requesting hidden link....
This file is requested by hidden link
What may cause this?
Arno
Hi Arno,
Would it be ok if I disabled all your non-toolset plugins to check if there are any issues with other plugins ?
Thanks,
Shane
Yes, no problem, but please enable the ones you disabled when you're done.
Thanks!
Arno
Hi Arno,
Not sure why but when all plugins were disabled and re-enabled the map starts to load.
I went ahead and disabled the spiderfy option for the map so overlapping markers will only show as 1 marker point. The only issue we're having now is that the clusters will show the number of markers that are intended to be there.
However based on what I'm seeing we won't be able to find a suitable solution to match exactly what you want to achieve.
Mainly because this view below is the one that is populating the markers and this is based on a relationship filter which is listing out the other items.
hidden link
Thanks,
Shane
Hi Shane,
I guess you were lucky there. I just disabled all plugins except Toolset, but still found the same map issue in another template. I have created a staging site where the problem still exists with only Toolset plugins and the 2022 theme. I currently still have Wordfence and 2 Kadence plugins enabled because templates look very messy without them, but even if disabling those plugins the problem is still there. The template "Tmp Regions-Search-Regions" is an example.
Do I need to open another support ticket for this? I already have a backup of the staging site in the location you already have access to. It's 2 zip files, dated May 4.
As for the original issue: so, by disabling Spiderfy there's actually multiple markers but only the one that happens to be on top can be clicked? Indeed it still shows the number of markers, but one could also interpret that as one marker showing 4 itineraries. I agree it's not ideal.
Kind regards,
Arno
Hi Arno,
I would recommend opening a separate ticket for that issue as we're handling the marker issue and it can be a bit confusing when we have multiple issue handling at once.
Secondly the only solution I can think of is if we have some unique identifier for the posts that are displayed with this view.
hidden link
Unfortunately I cannot immediately think of how we would set a unique identifier given how your data is arranged.
I was thinking of setting your view to display only 1 item which would resolve the issue, however this introduces the issue of where multiple locations for the same activity, then only the first location will be displayed.
Thanks,
Shane
Hi Shane,
Sure, I opened a new ticket.
If I was programming this, I'd have an array/collection of processed Location IDs while looping through them. On each Location I'd check the collection and skip the Location if its ID was already in the collection. I don't have enough Toolset experience to understand if something like that is possible.
As for your last suggestion, to only display 1 item: I don't fully understand the approach yet, but what I can say is that in this scenario we do have only 1 Location per Town. The structure is Itinerary <> Town <> Location, all many-to-many, but the Town-Location relation has a checkbox field "Main town location". In the view you referred to, I already only process the Locations with that checkbox set:
[wpv-conditional if=" '[types field='main-town-location' output='raw'][/types]' eq '1' "]
Normally only one Location has that checkbox set.
I hope this makes sense 🙂
Arno
FYI: the maps issue is solved, or at least there is a work-around: https://toolset.com/forums/topic/maps-block-throws-error-in-the-wordpress-editor/