Skip Navigation

[Resolved] How to see grandchild custom post with information of his parent and grandparent

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

Problem: I have 3 post types in a child -> parent -> grandparent hierarchy relationship. I would like to display information about the parent and grandparent in the child post.

Solution:
Access information about a parent post, you can use the following syntax:

[wpv-post-title id="$parent-type-slug"]

So for example, if your city post type slug is "city", then your code will be:

[wpv-post-title id="$city"]

To access information about a grandparent post, you can use a Content Template to change the context by passing in the $city operator for the id attribute:

[wpv-post-body id="$city" view_template="your-content-template-slug"]

Inside that Content Template, you can then use the parent post technique we used before to access the grandparent country post. If your country post type slug is "country" then your code in the Content Template will be:

[wpv-post-title id="$country"]

Relevant Documentation:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

This support ticket is created 6 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Rostislav Avtodiychuk 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#603855

I am trying to:

I have three custom post types: countries, cities, houses.
There are some post relations: countries(parent)-cities(child)-houses(child of city, so I think grandchild of countries)

Cities and Countries have post relations like:
France - Lyon, Marseille
USA - New York, Los Angeles
and etc. Yes, I've created postrelationships between Countries and Cities. It's all right at the back end.

When I have been creating houses, of course I've set post relations like:
houseinengland1 - child of London - (London is child of Great Britain)
HouseinUSA1 - child of New York - (New Your is child of USA)
HouseinUSA2 - child of Los Angeles - (Los Angeles is child of USA)
and etc.

I have houses and I want to see in single post layout next (for example):
My house
MarselHouse
is in the city of
Marseille
in the country
France

I've created two views "allcities" and "allcountry" and nevertheless how I've tried to filter them, I've never got the right result.

My custom template for single post "house"
<h3>My house</h3>
<h1>[wpv-post-title]</h1>
<h4>is in the city of [wpv-view name="allcities"]</h4>
<h4>in the country [wpv-view name="allcountry"]</h4>

Link to a page where the issue can be seen:

hidden link
hidden link
hidden link

I expected to see:

My house EnglandHouse is in the city of London in the country Great Britain.

Instead, I got:

Or nothing, or the all cities and countries like now.

#604081

Hi, to access information about a parent post, you can use the following syntax:

[wpv-post-title id="$parent-type-slug"]

So for example, if your city post type slug is "city", then your code will be:

[wpv-post-title id="$city"]

To access information about a grandparent post, you can use a Content Template to change the context by passing in the $city operator for the id attribute:

[wpv-post-body id="$city" view_template="your-content-template-slug"]

Inside that Content Template, you can then use the parent post technique we used before to access the grandparent country post. If your country post type slug is "country" then your code in the Content Template will be:

[wpv-post-title id="$country"]

More information about these techniques can be found here:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

#605752

Thank you very much! It's working fine like I've been dreaming of! Thanks for your help.