Skip Navigation

[Resolved] Get Custom Fields from second or third tier parent

This support ticket is created 3 years, 11 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
- 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/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 3 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1621579

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!

#1622387

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"]
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.