# Filter a list by user role

**URL:** <https://www.phphelp.com/t/filter-a-list-by-user-role/31890>\
**Category:** Help with WordPress\
**Created:** [May 18, 2020, 8:43pm UTC](https://www.phphelp.com/t/filter-a-list-by-user-role/31890 "2020-05-18T20:43:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TECTONIC](https://www.phphelp.com/user_avatar/www.phphelp.com/tectonic/32/3156_2.png) [@TECTONIC](https://www.phphelp.com/u/TECTONIC)\
**Post date:** [May 18, 2020, 8:43pm UTC](https://www.phphelp.com/t/filter-a-list-by-user-role/31890/1 "2020-05-18T20:43:52Z")

</div>

Hello all! So glad I found this forum. I would appreciate some assistance please.

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!

```auto
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);
    }
}

```
