php - Filtering a Wordpress admin post list by role

I'm working on a filter for a Custom Post Type . I need it to filter the list depending on the user's role. The way this should work is the following...
- Users in roles "formusers1" and "formusers2" can post. Users can only see their own posts.
- Users in role "formchecker1" can see all posts assigned role "formusers1' and can approve each post.
- Users in role "formchecker2" can see all posts assigned role "formusers2' and can approve each post.
- Users in roles "formsupervisor" and "administrator" can see everyone's posts.
So far I can filter by roles "formusers1" and "formusers2" using$query->set('author', $current_user->ID);
. However, when try to filter the list for role "formchecker1" I see posts from all roles. What am I doing wrong? Here's the rest of the code. Thanks for checking out!
add_action('pre_get_posts', 'filter_posts_list');
function filter_posts_list($query) {
//GLOBAL VARIABLES
global $pagenow, $typenow;
//MY VARIABLES
global $current_user;
get_currentuserinfo();
//FILTERING
if (current_user_can('formchecker1') && ('edit.php' == $pagenow) && $typenow == 'mycustomcpt' ) {
$query->set('author', 'formusers1');
}
if (current_user_can('formchecker2') && ('edit.php' == $pagenow) && $typenow == 'mycustomcpt' ) {
$query->set('author', 'formusers2');
}
if ((current_user_can('formusers1') || current_user_can('formusers2')) && ('edit.php' == $pagenow) && $typenow == 'mycustomcpt') {
$query->set('author', $current_user->ID);
}
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: an exception occurred in the driver: could not find driver
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.