I'm assigning some posts to some users whom are not the author of those posts. Typically private posts are visible only to the post authors. So, if the author has 3 posts, on his logged in edit.php
they will get 3 posts. But if another post is assigned to them by custom field (not as a post author), how can I add the post to the post list table?
What I tried so far is: making a function (custom_get_assigned_posts()
) to retrieve all the posts that are assigned to a user_id as an array. But then found that there's no easy way including post IDs into the existing query:
function add_assigned_posts( $query ) {
if( is_admin() && in_array( $query->get('post_type'), array('mycpt') ) ) {
global $current_user;
$query->set('post__in', custom_get_assigned_posts( $current_user->ID ) );
}
return $query;
}
add_filter( 'pre_get_posts', 'add_assigned_posts' );
But post__in
doesn't additionally include things, it actually specified posts to retrieve.
How can I include posts that are assigned to a non-author of posts, and are assigned by postmeta?