Skip Navigation

[Resolved] Showing Grandparent fields in a view from the listed grandparents.

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

Problem:

Query child posts in single grandparent posts.

Solution:

there isn't direct relationship between post type grandparent and child , so the nested view is required:

https://toolset.com/forums/topic/showing-grandparent-fields-in-a-view-from-the-listed-grandparents/#post-1220600

Relevant Documentation:

https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items

This support ticket is created 5 years, 10 months 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by CharleneD1435 5 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1220197

Tell us what you are trying to do?

My site excists out of 3 levels posts each one related to the other.

First level (grandparent) Monsters.

Second level (parent) Skills
Third level (child) Effects. Seperated in 3 different posts, beneficial effects, harmfull effects and other effects.

Is there any documentation that you are following?

I have read trough the showing grandparent fields tutorial but what I need to do seems to be in reverse.

What is the link to your site?

hidden link

So a little extra information, on the page you can see I have managed to create a grid of Monsters. Each of these monsters has 4 additional skills. Now these skills have additional effects.
Which is why I chose for the relationship Monsters > Skills < Effects.
Now I have 2 issues I am trying to solve, I wish to add a featured image from the Effects belonging to the skills of this particular monster preferably in a 4 column grid.
I've tried to do so by creating a view for effects and adding this view to the Skills view, but this does not have the result I'm wishing for.
This results in showing the effects on a skill basis. I wish to show the effects on a monster basis. So that my visitors can easily see in one eye wink which effects the monster has. My second issue with this view is that it shows "no items found" for each skill that does not have a relationship set yet. Not every skill will be having an effect so I'd like to condition my result by showing only the effects that are connected to the skills of this monster.

How would I go about this?

#1220600

Hello,

It is possible with a nested view.

For example, in a single "Monsters" post, setup a nested view as below:
1) Parent post view:
- Query posts of post type "Skills"
- Filter by the post type relationship between "Monsters" and "Skills"
- in section "Loop Editor", display "Skills" post information + below child post view

2) Child post view:
- Query posts of post type "Effects"
- Filter by the post type relationship between "Skills" and "Effects"
- in section "Loop Editor", display "Effects" post information

More help:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items
Displaying many related items

For the question:
I'd like to condition my result by showing only the effects that are connected to the skills of this monster

You can customize the text "no items found", for example, edit the child post view, in section "Loop Editor", find shortcodes:

	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]

And change it to what you want.
hidden link

#1220757

Hello Luo,

Thanks for getting back to me about this, however I believe you misunderstood my intention.
What you are describing above is what I already have at the moment.

Currently I am using a view, Monster view, to show all Monsters in a grid.
In this view I have a nested view, Skills View, that is set to show all skills in relationship to Monsters Skill.
Now within the Skills view, I have set up a Effects view, which shows per skill which effects are related.

However, this isn't what I wish to achieve.

What I wish to achieve is to have a monster view, and within this monster view I wish to nest both the Skills and Effects views.
Because I do not wish to show the effects per skill, I wish to show the effects per monster.
So basically I wish to show the grandchildren of the Monster post.

So My Grid should look like this:

Monster Image
Monster Title
Monster Stats
Effects

Skills

Instead what I get now with the nested views is

Monster Image
Monster Title
Monster Stats

Monster Skill
Effects
Monster Skill
Effects
Monster Skill Effects

And to clarify the 2nd point of interest, currently each skill that has no Effect relationship shows "no items found" I know I can set a different text for this but what I wish to do is IF no relationship is present not to show anything at all. I read in the tutorials about conditionals and empty fields but I couldn't make it work. So I was hoping you could help me out with how to set a conditional for the view effects, to show the results only if the results is not empty.

Hope that clarifies things a bit better sorry if I wasn't clear enough in the first post.

#1220762

Thanks for the clarifies.

As you can see, in your website, there isn't direct relationship between post type "Monster" and "Effects", so the nested view is required in this case.

As a workaround, you might consider add another one-to-many relationship between post type "Monster" and "Effects", then you will be able to achieve both:
1) In a single "Monster" post, setup a post view, display all related "Effects" posts
2) in above post view, display something else if there isn't any related "Effects" posts

#1220813

Thanks Luo,

I see so there is no possibility to show grandchildren in a view only grandparents by setting context id?
If I would put up a Monster - Effects relationship wouldn't I than need to set the relationships twice?
Once for the skill and once for the monster?

Also wouldn't one to many relationship mean that only one monster can have the effect assigned to it? The relationships are still quite a challenge for me so sorry if I misunderstand.

Thing is I have about 60 effects which are shared under 574 monsters who in total have about 2500 skills.
It is correct that the Monster only has a direct relationship with the skills, and the skills have a relationship with the effects. So if there's no way to add grandchildren perhaps I'll just have to settle with showing the effects by skill instead.

Thanks anyway though 🙂 I'll try your tip with the Monster Effect relationship and see how that works out.

#1221272

Yes, as I mentioned above, since there isn't direct relationship between post types "Monster" and "Effects", but you are going to query related "Effects" posts in "Monster" post, so it need to setup another relationship between "Monster" and "Effects", and you will need to set the relationships twice: Once for the skill and once for the monster

For the new question:
Also wouldn't one to many relationship mean that only one monster can have the effect assigned to it?
That depends on yourself.

If one "Monster" post can connect to multiple "Effects" posts,
and one "Effects" post can connect to multiple "Monster" posts,

Then you can setup many-to-many relationship between post types "Monster" and "Effects".

#1221400

Thank You I'll give that a try than 🙂