Skip Navigation

[Resolved] Conditional display of parent post

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

Problem: I would like to display some text and a custom field from a parent post within in my child post, but only if the child post has a parent post defined. If no parent is defined, I do not want to display anything here.

Solution: You can use the $parent-slug operator in a wpv-post-title or wpv-post-id shortcode to get information from a parent post type. If a parent of this post type is not defined, these fields are designed to fall back to display the child post. So, you can use a conditional that tests both IDs. If they are identical, then the parent is not defined. If they are different, then you know the parent is defined and the conditional is true.

[wpv‐conditional if="( '[wpv-post-id id='$client']' ne '[wpv-post-id]' )"]
[wpv-post-link id='$client']
[/wpv‐conditional]

Relevant Documentation: https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 7 years, 3 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 romanB-3 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#556936

Hello,
I am using this shortcode to show parent post name :

Client : [wpv-post-link id="$client"]

but when the "client" parent post is not set, the shortcode returns the current post name.
Therefore I need to only show the client if the client parent post is set.
How would I do this ?
Thank you.

#557030

You can set up a conditional that tests the value of the parent post's ID against the value of the child post's ID. If a parent post is not assigned, then the IDs will match. If a parent post is assigned, the IDs will be different.

[wpv-conditional if="( '[wpv-post-id id='$client']' ne '[wpv-post-id]' )"]
[wpv-post-link id='$client']
[/wpv-conditional]
#557051

Didn't think of that, but this works. Thank you.