Skip Navigation

[Resolved] Get Repeatable Group from Parent set by WordPress hierarchical relationship:

This thread is resolved. Here is a description of the problem and solution.

Problem:

I have the following structure in a CTP "Ratgeber" set by WordPress hierarchical relationship, how can I get the top tier parent "Ratgeber" post ID?

Solution:

It needs custom codes, to find out the top level(parent) "Ratgeber" post ID, please check similar thread:
https://wordpress.stackexchange.com/questions/315799/get-top-parent-url

Relevant Documentation:

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 2 replies, has 2 voices.

Last updated by hendrikH 3 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1621583

Hello Toolset Support,

Currently, I am using Toolset Repeatable Group with a "number" field to retrieve information via an API.
I have used the following code to retrieve the values of the fields into an array.


<?php
    $section_ids = toolset_get_related_posts(
        get_the_ID(),
        'pznsgroup',
        'parent',
        100,
        0,
        array('meta_key'=>'toolset-post-sortorder'),
        'post_id',
        'child'
    );
 
    $new_pzn = array();
 
    if ( $section_ids ){
    foreach ( $section_ids as $section_id ){
        $section = get_post_meta( $section_id, '', false );
        $section_content = $section["wpcf-pznnumber-ratgeber"][0];
 
        array_push($new_pzn, $section_content);
 
        }
     }
 
    if ( $new_pzn ){
 
 
        foreach ( $new_pzn as $single_new_pzn ){
 
            [... API stuff..]
 
?>

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

My question is: How can I get the values of the repeatable group from the top tier parent to all subsequent children.
Example:
"supplements" - has repeatable group fields filled and I want "vitamins", "vitamin d", "vitamin d deficiency" to have access to those values if their fields are not filled.

Thank you very much.

#1622397

Hello,

It needs custom codes, for example:
In a single "Ratgeber" post:
1) find out the top level(parent) "Ratgeber" post ID, see similar thread:
https://wordpress.stackexchange.com/questions/315799/get-top-parent-url

2) Then use above "Ratgeber" post ID to replace "get_the_ID()" of the PHP codes you mentioned above.

More help:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

#1628135

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.