Skip Navigation

[Resolved] Check whether post has a parent and get data from grandparent

This support ticket is created 4 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 3 replies, has 2 voices.

Last updated by Luo Yang 4 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1787947
Bildschirmfoto 2020-09-23 um 19.14.41.png

On artagenda.com, we have CPT Venue (think of: museum, gallery), Exhibition and Event.
Post relationships:
- An Exhibition has a Venue as parent.
- An Event can have an Exhibition as parent (think of: guided tour through an exhibition)
- An Event can also (directly) have a Venue as parent (think of: 50 years anniversary of Museum X)

To display the location of an event, I need to check first whether there is a specific location indicated in the post. If this is not the case, the location information should be taken from:
- if there is a parent Exhibition: The location of the parent's Exhibition parent Venue
- if there is a parent Venue: The location of the parent Venue

So I need to check whether there is a post relationship or not, and then (eventually) get information from the grandparent post.

I couldn't find any documentation for these two issues.

A similar example is in every exhibition on artagenda.com (e.g. hidden link), where the bottom is fairly straightforward displaying data from the parent Venue. The challenge is now to go one level further, with events belonging to exhibitions.

I am grateful for any hint!

#1788621

Hello,

You can get parent post ID with item attribute, for example:
[wpv-post-id item="@RELATIONSHIP-SLUG.parent"]
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

Then use it in [wpv-conditional] shortcode to check above shortcode value is empty or not, then display what you want, see our document:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/conditional-output-based-on-post-relationships/

#1791755

Hi Luo,

thank you for your reply! Yes, this is the way to go.

Regarding the grandparent question: Can the .parent be nested? I need to fetch fields from the parent venue of the parent exhibition, so this would be [wpv-post-id item="venue_exhibition.parent [wpv-post-id item="exhibition_event.parent“]“]?

The terminology in my current content templates is completely different from this one. The parent is called by id="$venue", e.g. [types field="venue_publictransport" id="$venue"][/types]. I am a bit confused now, are there two different ways to call the very same function?

Thank you for your help!

#1792349

Q1) Can the .parent be nested?
No, it can not be nested, for grand parent post, you can try these:
1) Create a content template "parent-post-info", in it's content, display the grand parent post information, for example:
[wpv-post-id item="@GRAND-RELATIONSHIP-SLUG.parent"]

2) In the single grandchild post content, display above content template with similar way:
[wpv-post-body view_template="parent-post-info" item="@PARENT-RELATIONSHIP-SLUG.parent"]
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-body

Q2) I am a bit confused now, are there two different ways to call the very same function?
The "id" attribute is retired, in the latest version of Toolset plugins, please follow the document I mentioned above to display related post information with "item" attribute.