I am engaged on a filter for a Customized Put up Sort . I want it to filter the listing relying on the person’s position. The way in which this could work is the next…
- Customers in roles “formusers1” and “formusers2” can submit. Customers can solely see their very own posts.
- Customers in position “formchecker1” can see all posts assigned position “formusers1′ and might approve every submit.
- Customers in position “formchecker2” can see all posts assigned position “formusers2′ and might approve every submit.
- Customers in roles “formsupervisor” and “administrator” can see everybody’s posts.
Thus far I can filter by roles “formusers1” and “formusers2” utilizing $query->set('writer', $current_user->ID);
. Nonetheless, when attempt to filter the listing for position “formchecker1” I see posts from all roles. What am I doing unsuitable? This is the remainder of the code. Thanks for trying out!
add_action('pre_get_posts', 'filter_posts_list');
perform filter_posts_list($question)
{
//GLOBAL VARIABLES
world $pagenow, $typenow;
//MY VARIABLES
world $current_user;
get_currentuserinfo();
//FILTERING
if(current_user_can('formchecker1') && ('edit.php' == $pagenow) && $typenow == 'mycustomcpt' )
{
$query->set('writer', 'formusers1');
}
if(current_user_can('formchecker2') && ('edit.php' == $pagenow) && $typenow == 'mycustomcpt' )
{
$query->set('writer', 'formusers2');
}
if( (current_user_can('formusers1') || current_user_can('formusers2')) && ('edit.php' == $pagenow) && $typenow == 'mycustomcpt')
{
$query->set('writer', $current_user->ID);
}
}