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!
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/
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!
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.