Hi,
I'm having an issue with getting the repeatable field group items which are child of a page.
When I do the query (screenshot of query uploaded) I get all the repeatable field groups that are also child of other pages, so not just the RFG's of that specific page. An echo of the $post->ID returns the specific ID. Just removing the 'toolset_relationships' query yields the same result, so it seems to ignore that completely.
I would like to do this as a wp_query, so no View. Website is made in combination with 'Timber'.
Thanks in advance!
Hi,
Thank you for contacting us and I'd be happy to assist.
I haven't used 'Timber' before, but using simple PHP code and "WP_Query", I was able to make the Toolset relationship query work:
( for parent post with ID 6 )
$args = array(
'post_type' => 'block',
'numberposts' => -1,
'order' => 'ASC',
'toolset_relationships' => array(
'role' => 'child',
'related_to' => 6,
'relationship' => 'block'
),
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ){
$the_query->the_post();
the_title();
echo '<br />';
}
Alternatively, you can also use the "toolset_get_related_posts" function, directly:
( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts )
$child_ids = toolset_get_related_posts(
6,
'block',
'parent',
100,
0,
array(),
'post_id',
'child'
);
if ( $child_ids ){
foreach ( $child_ids as $child_id ){
echo get_the_title($child_id);
echo '<br />';
}
}
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Hi,
Thanks for the reply. I don't get it to work with the query. There seems to be a problem with the RFG's in combination with Timber because if if use get_posts on a post of the RFG I get no results even though the ID clearly exists.. Using the query you provided yields all the posts of the RFG regardless of the page ID I query.
I got it to work with toolset_get_related_posts and then foreach loop over all the fields I need. That way I only get the childs of the specific page.
Thanks for the help!
My issue is resolved now. Thank you!