I have 2 user groups: authors and clients
Authors can publish posts and specify in metabox for wich client these post is ment for.
Client can publish posts and view, edit posts, created by Authors for them.
Problem:
In wp-admin on posts screen ( wp-admin/edit.php ) i need to display:
if Author: only author posts
if Client: client posts and posts where meta value is client id
if admins: all posts
I'v added pre_get_posts
filter to filter only author posts:
/**
* Show only author posts, but all for admins
**/
function m7_24_ee_posts_for_current_author( $query ) {
if( $query->is_admin && 'post' == $query->query_vars['post_type'] && ! current_user_can( 'administrator' ) ) {
global $user_ID;
$query->set( 'author', $user_ID );
if( current_user_can( 'client' ) ) {
$query->set( 'meta_key', 'client' );
$query->set( 'meta_value', $user_ID );
}
}
return $query;
}
add_filter( 'pre_get_posts', 'm7_24_ee_posts_for_current_author' );
But the problem is that meta_key
and author
fields acts like AND
, but i need them to be 'OR`. or author is $user_ID or meta_value is $user_ID
If there's no easy solution for these than it can be made by marging 2 queryies ( 1 with author and 2 with meta value ), but the problem is that i don't know which hook should i use to marge them, becouse pre_get_posts
is fiering to early.