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?
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.
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?
My issue is resolved now. Thank you!