Hello Toolset Support,
I have the following structure in a CTP "Ratgeber" set by WordPress hierarchical relationship:
supplements - parent
vitamins - child of supplements
vitamin d - child of vitamins
vitamin d deficiency - child of vitamin d
In the parent post "supplements" I have filled the custom field "wpcf-landingpage-url". My goal is to get this value across all child posts directly/indirectly.
At the moment I have the following code:
[wpv-conditional if="( $(wpcf-landingpage-url) ne '' )"]
<a href="[types field='landingpage-url' output='raw'][/types]" target="_blank" rel="noopener noreferrer">
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-landingpage-url) eq '' )"]
<a href="[types field='landingpage-url' output='raw' item='$parent'][/types]" target="_blank" rel="noopener noreferrer">
[/wpv-conditional]
</a>
This works fine form the first tier child, like "vitamins", but for the second/third tier elements, this does not work anymore. I understand why but I can't get my head around it. Is there a solution to this?
Thank you!
Hello,
You can try these:
1) Create a content template "parent-ratgeber-information", with the codes you mentioned above:
[wpv-conditional if="( $(wpcf-landingpage-url) ne '' )"]
<a href="[types field='landingpage-url' output='raw'][/types]" target="_blank" rel="noopener noreferrer">
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-landingpage-url) eq '' )"]
<a href="[types field='landingpage-url' output='raw' item='$parent'][/types]" target="_blank" rel="noopener noreferrer">
[/wpv-conditional]
</a>
2) In a single first tier child "ratgeber" post, you can display above content template with below shortcode:
[wpv-post-body view_template="parent-ratgeber-information" item="$parent"]
More help:
https://toolset.com/documentation/user-guides/views/views-shortcodes/item-attribute/
$parent is used to retrieve data from a hierarchical parent if the current post is a type of hierarchical post such as a page. If the reference does not match an existing post, the data from the current post will be returned.
3) Same as above, you can create another content template "first-tier-child-ratgeber-post", with the same codes of step 2):
[wpv-post-body view_template="parent-ratgeber-information" item="$parent"]
In the second tier child "ratgeber" post, display above content template shortcode, like this:
[wpv-post-body view_template="first-tier-child-ratgeber-post" item="$parent"]