我试图在WordPress管理中过滤帖子页面,以显示符合“A”或“B”标准的帖子。我仔细查看了文档,找不到一个好的方法来完成这项工作。
详细信息:我已经确定了用户角色的范围,因此作者只能编辑自己的帖子。然而,我已经添加了一个自定义字段,以便作者可以选择其他作者来编辑文章。如果我在“parse\\u query”过滤器中使用一个或另一个,则此功能非常有效,但如果我尝试同时启用这两个查询,则认为我希望显示符合所有条件的帖子(无)。
以下是我的代码(位于functions.php中),以供参考:
add_filter(\'parse_query\', \'show_appropriate_posts\');
function show_appropriate_posts($query) {
if ( strpos($_SERVER[ \'REQUEST_URI\' ], \'/wp-admin/edit.php\') !== false ) {
if ( !current_user_can(\'manage_options\') ) {
global $current_user;
//Only list posts by this user (A).
$query->set(\'author\', $current_user->id);
//List posts this user is "tagged" in (B).
$query->set(\'meta_key\', \'add_editing_permission_for\');
$query->set(\'meta_value\', $current_user->id);
$query->set(\'meta_compare\', \'LIKE\');
//@TODO: Need to show posts that meet (A) -or- (B).
}
}
}
同样,单独运行时,(A)和(B)都工作。