Skip Navigation

[Resolved] Cannot display child posts – Set up seems correct but need verification

This support ticket is created 6 years, 6 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.

This topic contains 1 reply, has 2 voices.

Last updated by Beda 6 years, 6 months ago.

Author
Posts
#916820
Screen Shot 2018-06-22 at 2.49.43 PM.png
Screen Shot 2018-06-22 at 2.48.00 PM.png

I am trying to display child posts on a page

Link to a page where the issue can be seen:
hidden link

I expected to see Quick possessions of that home model showing in the section specified

Here is the code being used:

<?php

$child_args = array(
'post_type' => 'quick-possession',
'numberposts' => -1,
'order' => 'ASC',
'toolset_relationships' => array(
'role' => 'child',
'related_to' => get_the_ID(),
'relationship' => array( 'home-model', 'quick-possession' )
)
);

$query = new WP_Query( $child_args );
while($query->have_posts()) : $query->the_post();

$title = get_the_title();

?>

<article class='col s12 m6 l4' >
<h4></h4>
</article>

<?php endwhile; wp_reset_postdata();?>

#916913

That is a new, not migrated Post Relationship.

Hence, the right API to use is toolset_get_related_posts():
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

Example:

$books = toolset_get_related_posts(
    $writer, // get posts related to this one
    array( 'writer', 'book' ), // relationship between the posts
    'parent', // get posts where $writer is the parent in given relationship
    $posts_per_page, $current_page, // pagination
    array( 's' => 'Harry' ), // How was his surname, again…?
    'post_object'
);

The code you use is for Legacy Relationships and migrated sites, which I do not see to be the case this Relationship on your site:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/

Please let me know if you have any more questions in regard?