我有2个用户组:authors 和clients
作者可以发布帖子并在metabox for wich中指定client 这些职位是为。
客户端可以发布帖子并查看、编辑帖子,创建人Authors 为了他们。
Problem:
在wp admin on posts屏幕(wp admin/edit.php)中,我需要显示:如果Author: 仅限作者帖子
如果Client: 客户帖子和帖子where meta value is client id
如果admins: 所有帖子
已添加I\'vpre_get_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\' );
但问题是meta_key
和author
字段的行为类似AND
, 但我需要他们是“或”。or author is $user_ID or meta_value is $user_ID如果这些问题没有简单的解决方案,那么可以通过将2个查询(1个带作者,2个带元值)加上边框来解决,但问题是我不知道应该使用哪个钩子来加边框,因为pre_get_posts
火烧得很早。