Skip Navigation

[Resolved] Displaying Grandparents – grandchild relationships in Slider

This support ticket is created 5 years, 1 month 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 8 replies, has 3 voices.

Last updated by Nigel 5 years ago.

Assisted by: Nigel.

Author
Posts
#1256435
0001-final.jpg

Tell us what you are trying to do? I set the relationships One-to-many between CPTs in hierarchy order: Continents, Countries, Regions, Destinations, Attractions. I want to make a slider on Regions page using images from related Attractions (grandchild) and Post title from Destination (child). Later, I want to do the same thing for Countries displaying images of Attraction (grand grandchild), Post title from Regions (child) and Post title from Destinations (grandchild). The same goes for the Continents page.

Is there any documentation that you are following? https://toolset.com/forums/topic/how-to-see-grandchild-custom-post-with-information-of-his-parent-and-grandparent/
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-fields-of-grandparents/

Is there a similar example that we can see?

What is the link to your site? hidden link

#1256841

Hi Kenneth,

Thank you for contacting us and I'll be happy to assist.

Your requirement can be split into two parts:

1. Getting the data from grandparent or grandchildren posts:

To show related posts data (whether it is parent or child), you can create a view, and set it to show the related posts using the post-relationship filter, as explained in this guide:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/

In the case of grandparent or grandchildren, the only difference would be that you'll be using the nested views, to show the data from each next parent or child level.

For example, suppose you need some post data from the "Attractions" post type ( which is at the lowest level of hierarchy ), while you're on a "Continents" post page ( which is at the highest level of hierarchy ).

To achieve this, you'll create the following views:

a. A parent view to show the "Countries" related to the current "Continent".
b. In that view, you'll nest another view that will show, related "Regions".
c. In that new view, you'll nest another view that will show, related "Destinations".
d. At the last level, you'll nest another view that will show, related "Attractions".

As a result, you'll have the information about the connected "Attractions" on the "Continent" page.

Here is a useful guide on the topic of nested views:
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

2. Showing that data in a slider:

Once you'll have the data from the posts that you'd like to show the slides from, you can use these step by step guides, to generate an image slider:
https://toolset.com/documentation/user-guides/creating-sliders-with-types-and-views/
https://toolset.com/documentation/beyond-the-basics/showcase-content-using-post-sliders/

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1258353

Thank you Waqar,

still don't get what is supposed to be. Can you make one example on my site in order to see where to put nested views? How can I send you credentials in private?

Thanks

#1260091

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Waqar is away, let me see if I can help.

I've set up a private reply to get credentials from you.

I'll create a sample series of Views as described by Waqar above to demonstrate what's involved.

Be sure you have a current backup please.

#1260257

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

I want to make a slider on Regions page using images from related Attractions (grandchild) and Post title from Destination (child).

Reading your question more closely what you need is a little different than Waqar described (how to traverse up and down a relationship hierarchy), and this is how I envisage this working.

You want a slider of attraction images, which means the main motor for this will be a View which queries attractions and which outputs them as slides. The images for the slides will come directly from the attraction posts. The titles should come from the parent destination.

When going from many to one (e.g. from child to parent) as you insert a field using the Fields and Views button you will have a Post selection tab available where you can specify that the field should come not from the current post but from some other post, e.g. a parent. which is what we need in this case, so your wpv-post-title shortcode for the title would get an "item" attribute added which indicates which post should be the source for the field.

(Going from one to many, e.g. from parent to child, the same isn't possible because there could be any number of children, and a View is required to list them in this case.)

So, you should be able to follow this guide to create a slider View for attractions which displays the parent destination for the title: https://toolset.com/documentation/user-guides/creating-sliders-with-types-and-views/

The problem is right now that this View would be displaying any attractions, and not just those which are grandchildren of the current region.

So we need to set up the context and then add a Query Filter to this slider View to limit which attractions are returned.

We can't used nested Views here because that implies generating multiple instances of Views, and the requirement that we output this as a slider means we need to end up with a single View.

So we need to add a Query Filter to our attractions View so that the attractions are related to destinations which we pass as a comma separated list using a shortcode attribute (see https://toolset.com/documentation/user-guides/passing-arguments-to-views/).

You need to create a View that queries Destinations and which includes a Query Filter to limit the results to destinations related to the region where this View is shown. Then in the output section we need to disable the wrapper div and output the destinations as a comma-separated list of post ids.

Then, when we insert the attractions View we can use this second View to provide the list of destinations that the attractions must belong to.

I'm out of time today, so if you can follow the above (I know it's complicated) and want to try, let me know how you get on.

If not I'll take a look again tomorrow.

#1260745

Thank you, Nigel,

LOL, I thought I've gone insane, unsuccessfully trying to achieve what I need to.

Nevertheless, it is so complicated to understand the whole structure of inserted Views and relationships. Can you help and show this on a sample, View is called Testing Regions Slider. This view is just a copy from another slider (showing attractions on destinations page, with the stylings).

I am using Elementor just as a placeholder for the views, none of the stylings goes from Elementor.

You can check the display of this slider here hidden link

Thank you in advance.

#1261121

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

OK, I have this working, although it might require an essay to explain.

To recap, the View "Testing Regions Slider" generates the slider from attractions posts.

Without a Query Filter it will display all attractions.

In the proposed solution I had described above we were going to pass a list of destination post IDs (belonging to the currently displayed region) to the View to use in a post relationship filter to only display attractions belonging to any of those destinations.

But I hit a brick wall, neglecting that the post relationship filter doesn't support multiple post IDs, you can only pass a single post ID, so it could only be used to display the attractions of a single destination in this context.

So, an alternative approach is that we will have to spoon-feed the actual list of attractions post ids that the View should operate on. So if you edit the View you will see that I have added a Query Filter for post ids, such that the ids of the posts that the View should return are passed via a shortcode attribute "ids".

Note that in your Elementor template for single regions I had to remove the View widget for the slider View because you cannot pass shortcode attributes to the View when inserted as a widget, it must be inserted as a shortcode inside a text widget, which is what I've done.

Now, where do we get the list of attraction post ids from?

Nested Views.

I created an outer View "outer - destinations of a region" which loops over destinations belonging to the current region but which doesn't output anything directly itself, it instead calls a second View "inner - attractions of a destination" which includes a relationship filter to return attractions belonging to the current destination in the loop and which outputs their post ids as a comma-separated list. In each case we are disabling the wrapper div, because we need a clean result such as "56, 345, 412, 416" etc. We'll actually have a trailing comma, but that won't matter.

So the outer View will produce such a comma-separated list of post ids, which we then pass to the slider View using the ids attribute, like so:

[wpv-view name='testing-regions-slider' ids="[wpv-view name='outer-destinations-of-a-region']"]

I've tested it on your site and it appears to be working.

Hopefully there is enough detail there for you to be able to adapt for other scenarios as needed.

#1262057
Image 2.jpg
Image 1.jpg

Thank you very much, Nigel.

It is working like a charm, exactly what I need. Although, it is advanced Toolset knowledge for the rookie I am.
I tested this slider and, for example, it shows Attraction from the Loire Valley destination as well as L'Astrance from the Paris Destination - both destinations belong to a Region called - Paris and Northern France. hidden link

I added one more Query to manually filter the related attractions with a checkbox (see image 1 and 2).

I will try to adapt this scenario for the Country and Continent templates.

#1262135

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Great.

Although your use-case might seem simple enough to you, the implementation details are indeed fairly complex.

It required a bit of head-scratching from me before I hit on a working solution, and I know Toolset quite well 😉

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.