Problem: I would like to be able to use a conditional that tests whether a hierarchical page has child pages underneath it.
Solution: One way to approach this is to use a View of your CPT filtered by Post Parent (not Post Relationship), where the parent post is whatever parent post you want to test. Depending on how you have things set up, the parent post could be the current post, or the current post in the loop, or you could provide a post ID in a shortcode attribute, etc.
Then in the Loop Output area of this View, you can use the items found and no items found sections to include different content based on the number of results. If results are found, you know the current post has children. If not, you know the current post has no children.
Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/
https://toolset.com/documentation/user-guides/digging-into-view-outputs/
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 6 years, 10 months ago.
Assisted by: Christian Cox.