Skip Navigation

[Resolved] PHP to query a repeating field group and return its parent

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.

This topic contains 3 replies, has 2 voices.

Last updated by Christopher Amirian 8 months, 4 weeks ago.

Assisted by: Christopher Amirian.

Author
Posts
#2690078

Is it possible to query in PHP a repeating field group and return the "parent" post for the RFG? I can't find any documentation on this.

#2690136

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

If I understand you correclty you want to get a parent pst of the repeatable field group.

This method can help I think:

https://toolset.com/forums/topic/create-a-view-that-lists-all-posts-with-repeatable-field-groups/#post-1191399

There is no GUI to achieve such a thing.

#2690139

No sorry I need to know how to do this in PHP using the API. I'm creating a function which needs to get the parent post from an RFG. I don't want to use a view for this.

#2690472

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Thank you for the clarification, you can use the toolset_get_related_post API:

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

To get the related parent post of the repeating field group item, please make sure that:

1. 'get_the_ID' is returning the current repeating field group item's post ID

AND

2. The slug of the relationship is the same as the repeating field group. For example, if the repeating field group slug is 'days1', then the relationship slug should also be 'days1'. A sample code:

$parent_posts = toolset_get_related_posts( get_the_ID(), 'days1', array( 'query_by_role' => 'child', 'return' => 'post_object' ) );

Thanks.

#2690700

Thanks. Can I suggest that the documentation here could do with a review https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/ A few more examples in the documentation would be helpful as it is very difficult to understand what is required for each of these. Thuis would cut down support requests I think

Also the solution given here seems to be wrong in that it refers to providing the relationship slug, and not the single post slug https://toolset.com/forums/topic/toolset_get_related_posts-documentation/

Finally, nothing anywhere that I can find refers to the RFG solution being the same as a parent/child solution.