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