[Résolu] For Beda please (re-opening previous ticket)
This support ticket is created Il y a 4 années et 9 mois. 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.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
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,
array(
'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
)
);