Skip Navigation

[Resolved] Conditionally display output based on the presence of a post relationship

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

Problem:
Conditionally display output based on the presence of a post relationship

Solution:

With Types 3.X.X, you should try to use following code to check if parent exists or not.

To check if parent exists:

[wpv-conditional if="( '[wpv-post-id item="@relationship-slug.parent"]' ne '' )"]
  
parent exists
  
[/wpv-conditional]

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/conditionally-display-output-based-on-the-presence-of-a-post-relationship/#post-917316

Relevant Documentation:

This support ticket is created 6 years, 6 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by josephQ 6 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#917146
Screen Shot 2018-06-24 at 15.56.18.png

Tell us what you are trying to do? I have a post type called Alumni. There is a relationship between this post type and another post type called Thesis Work. An Alumni may be connected to zero or more Thesis Works. I'd like to show some content—specifically, a subheader named "Thesis Works"—if there is at least one Thesis Work connected to the Alumni whose page is being viewed. I've attached a screenshot of the Layout work-in-progress. Right now, the subheader "Thesis Works" appears whether or not there are Thesis Work post types connected to the given Alumni. See the URL below for front-end view.

Is there a way to conditionally display a piece of information based on the presence of a post relationship? I didn't see a way to do this through the Conditional Output dialog.

Is there any documentation that you are following? No.

Is there a similar example that we can see? No.

What is the link to your site? hidden link

#917316

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - With Types 3.X.X, you should try to use following code to check if parent exists or not.

To check if parent exists:

[wpv-conditional if="( '[wpv-post-id item="@relationship-slug.parent"]' ne '' )"]
 
parent exists
 
[/wpv-conditional]

Where:
- Replace relationship-slug with your original post relationship slug.

#917919

Minesh, thanks for the snippet of code! I haven't had a chance to try it, but if it doesn't work I'll reopen the ticket. Thank you again!

#918142

So I tried this snippet of code, and it didn't work as expected. I think the issue is that the code is checking for a post ID of a parent post. But I'm *viewing* the parent post. What I want to do is check for the presence of any *child* posts.

Can we replace "parent" with "child" in your snippet, per below?

[wpv-conditional if="( '[wpv-post-id item="@relationship-slug.child"]' ne '' )"]
parent exists
[/wpv-conditional]

I'm working in the "Template for Students Layout" at hidden link. An example page on the front-end is hidden link.

#918181

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - as I mentioned with my previous reply here:
=> https://toolset.com/forums/topic/conditionally-display-output-based-on-the-presence-of-a-post-relationship/#post-917316

your original query is to check the parent post exists or not. Could you please open a new ticket with your each new question. This will help users searching on the forum and help us to write the resolve ticket summery to the correct issue which is raised with your original question.

Thank you for understanding.

#918315

OK, will do. My apologies for not following proper protocol. I'll open a new ticket for each new question going forward; I'd been afraid to separate issues that were so closely related.

Thanks, Minesh!