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?
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