Tell us what you are trying to do?
I have a one to many relationship (chart -> data).
I need to get the related child posts (data posts) belonging to a parent (chart).
But I only need the posts of a certain author.
Is there any documentation that you are following?
Toolset relationships api
I tried using the toolset_get_related_posts() function but it does not allow to filter by author.
This would really be a great feature to include!
So i tried storing user info in a post meta field (wpcf-student-id) and adding it to the query arguments.
$records = toolset_get_related_posts(
$chart, // get posts related to this one
'chart-record', // relationship between the posts
'parent', // get posts where post is the parent in given relationship
999, //number of post
0, // pagination
array(
'meta_key' => 'wpcf-student-id',
'meta_value' => $_GET['uid'],
'meta_compare' => '=',
), // Additional query arguments
'post_object' // return type
);
This however does not return the child posts (It returns an empty array).
If I remove the meta query I do get all the child posts (not filtered by author), so I guess the problem is restricted to that part.
Am I using the meta query in the wrong way?
Any help would be very much appreciated.
Cheers,
Tako
Hi, unfortunately post author isn't currently implemented in the toolset_get_related_posts API, but check out this document with examples showing how to implement toolset relationship criteria in a standard WP_Query:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/
You can add post author criteria to a WP_Query, which may achieve what you're looking for. Pay close attention to the remarks section at the bottom of the post for information about timing and when these filter options are available in the request lifecycle.
This however does not return the child posts (It returns an empty array).
One thing I can see is that there is no "role_name_to_return" argument supplied. It's required. After the 'post_object' parameter, add 'child'. But as I was saying, post author can be added to WP_Query along with toolset relationship criteria for a more robust, flexible query filter.
Hi Christian,
Thank you for the reply.
Implementing the toolset relationships in the standard WP_Query is very powerful and fixes anything I needed to do.
Thanks for the help.
Cheers,
Tako