Skip Navigation

[Resolved] toolset_get_related_posts() only returns 1st post

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 2 months, 3 weeks ago.

Assisted by: Nigel.

Author
Posts
#2726841

Tell us what you are trying to do?
Trying to get the related children of a CPT. They show in a view but when i call the API it returns only post
toolset_get_related_posts()

Is there any documentation that you are following?
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
Is there a similar example that we can see?

What is the link to your site?
happy to provide credentials

#2726851

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Do you have an example of the code you are using, I might be able to spot a problem.

#2727713

The error log produces the contractor id that i would expect. The vehicles array only shows 1 vehicle. I can see on the post that it has a toolset relationship with 2 vehicles.
error_log($contractor_id);
// Retrieve related vehicles
$vehicles = toolset_get_related_posts($contractor_id, 'contractor-vehicle', 'child', [
'post_status' => 'publish',
'posts_per_page' => -1
]);
print_r($vehicles);

#2728365

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I reviewed the API documentation and I think you need to use it like this for the results you want:

toolset_get_related_posts( $contractor_id, 'contractor-vehicle', 
    [
    'query_by_role' => 'parent',
    'limit'         => -1,
    'args'          =>  [
                         'post_status' => 'publish'
                        ],
    'role_to_return'    => 'child'
    ] 
);