Skip Navigation

[Resolved] Check if a page is a subpage (same CPT) and then show content

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

Problem: I have a hierarchical post type. I would like to use conditional HTML to determine if the post is a top level post, or if the post has a parent.

Solution: Use the post ID in the conditional:

[wpv-conditional if="([wpv-post-id item='$parent'] ne [wpv-post-id])"] this is a subpage [/wpv-conditional]
This support ticket is created 5 years, 7 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 Zayne 5 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1275123

I need to group lists of Works (CPT) together, for instance when there are 5 individual works in a Suite of works. When I view one of the individual works, I want to be able to show a link to the parent work. I know I can do this with [wpv-post-link item="$parent"], but the issue is that I want to add the title "Parent Work:" whenever there is one. When there isn't a parent work, I don't want the title to show. Thus I need to use a conditional. However, I can't get any conditional to work.

I've tried

[wpv-conditional if="[wpv-post-link item="$parent"] ne ''" ]

and many other combinations of this, but nothing works. What can I do?

#1275153

Hi, you can use the post ID shortcode to test whether there is a hierarchical parent post ID that is different from the current post ID. The system will return the current post's ID if no hierarchical parent post exists.

[wpv-conditional if="([wpv-post-id item='$parent'] ne [wpv-post-id])"] this is a subpage [/wpv-conditional]
#1275195

Aha! Thanks for the help.