Skip Navigation

[Resolved] Create child posts relationship list on post page in php

This support ticket is created 3 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.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by xiaolinW 3 years, 6 months ago.

Assisted by: Jamal.

Author
Posts
#2057721

Hi, I'm creating a template entirely in php, I have a custom post type parent and one child, how can I create a list of all child posts for every parent post?

I know how to retrieve child posts ids by using https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

But how can I make the pagination or infinite scroll?

#2057837

Hello and thank you for contacting the Toolset support.

Both pagination and infinite scroll will depend on how you want to implement it. From the API level, you can set the limit and offset in the third param:

$posts = toolset_get_related_posts( $post_id, 'relationship-slug', array(
    limit: 10,
    offset: 10
));

This will return 10 posts after the first 10 posts, which is equivalent to the second page with 10 posts per page.

For pagination, you may want to rely on a URL parameter, for example, hidden link
And based on its value(2), you can set the limit and the offset accordingly.

For infinite scroll, you will need to implement an AJAX handler to return the additional pages. Read more about WordPress's AJAX here https://developer.wordpress.org/plugins/javascript/ajax/
And check this tutorial here hidden link

I hope this helps. Let me know if you have any questions.

#2058065

Thanks for the explanation, and what if I want to create a list of child/parent posts list view with toolset and display it in the php code?

#2058123

You can the render_view function. Read more about it here https://toolset.com/documentation/programmer-reference/views-api/#render_view

#2058443

My issue is resolved now. Thank you!