Skip Navigation

[Resolved] Show text in parent template if parent has child in one-to-many relation

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by rubenM-3 2 years ago.

Assisted by: Waqar.

Author
Posts
#2503133

Hi,
I'm using block editor to create a template for a CPT, thas has a one-to-many relation with other CPT. I can see childs in parent page, but I'd like to hide a header ("Les nostres sales"), if parent has no children. Children is shown in a View created with block editor.

hidden link

How can I create a conditional "has chiilds", for showing or not the header before the childs' View?

#2503689

Hi,

Thank you for contacting us and I'd be happy to assist.

You can use the item attribute in Toolset shortcodes like 'wpv-post-id' to get the ID of the related post:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-id

For example, if the relationship slug is 'company-branch', the following shortcode will return the ID of one of the related child posts, if it exists:


[wpv-post-id item="@company-branch.child"]

In your conditional block, you can switch to the 'advance editor' to manually enter the conditional statement and use this shortcode, like this:


NOT ( empty( '[wpv-post-id item="@company-branch.child"]') )

So anything enclosed within this conditional block will only show if there is at least one related child post attached to the current parent post.

I hope this helps and please let me know if you need any further assistance with this.

regards,
Waqar

#2503707

This is great! Thanks!