In my scenario I need to get the post ID of the draft child post when there are multiple child posts. I set this up:-
Post types: 'my-parent-post' & 'my-child-post' in a one-to-many relationship
Parent post id is 3660
4 x child posts: 3663 (publish), 3668 (draft), 3673 (pending), 3678 (private)
View filtering for 'my-parent-post' containing shortcode [child_post] to display the post IDs of draft child post(s)
Shortcode looks like this:-
I expected to see 3668 (the ID of the draft child post) but I get this error "PHP Fatal error: Uncaught InvalidArgumentException: Limit must be a non-negative integer or -1". If I change the function to toolset_get_related_post instead, the shortcode returns 0.
Have I misunderstood what toolset_get_related_posts returns or is my shortcode wrong somewhere?
Note that the second argument—for the relationship—should be the relationship slug, unless this is an old Types-2 relationship that hasn't been migrated, when you pass the parent and child as an array (which you have done, probably incorrectly).
Here's an annotated example of how to use it:
$children = toolset_get_related_posts(
$post->ID, // ID of origin post
"my-parent-my-child", // relationship slug,
'query_by_role' => 'parent', // role of origin
'role_to_return' => 'child', // role to return
'return' => 'post_id', // (optional) what to return, IDs or objects
'limit' => -1, // (optional) limit
'offset' => 0, // (optional) offset
'args' => array( // (optional) array of additional query arguments
'post_status' => 'draft'
'orderby' => 'title', // (optional) orderby setting
'order' => 'ASC', // (optional) order direction
'need_found_rows' => false // (optional) whether to include number of results