这可以通过parse_query 过滤器,如下所示:
add_action (\'parse_query\', array ($this, \'wpse_private_author_query\')) ;
function
wpse_private_author_query ($query)
{
// get our private author query query_var
$private_author_query = $query->get (\'_private_author_query\') ;
if (empty ($private_author_query)) {
// our private author query query_var is not set, so bail without modifying $query
return ;
}
$args = array (
\'fields\' => \'ID\',
) ;
$args = wp_parse_args ($args, $private_author_query) ;
// get the ID\'s of the users that match our private author query
$users = get_users ($args) ;
// unset our private author query query_var
unset ($query->query_vars[\'_private_author_query\']) ;
// add the author IDs to the query
$query->set (\'author__in\', $users) ;
return ;
}
要看到这一点,我们可以:
$args = array (
\'post_type\' => \'any\',
\'post_status\' => \'public\',
\'_private_author_query\' => array (
\'meta_key\' => \'meta1\',
\'meta_value\' => true,
\'meta_compare\' => \'=\',
),
) ;
$posts = new WP_Query ($args) ;
Note: 以上内容比你的问题更笼统。您只请求了user\\u meta,但上面的命令将允许通过支持的任何特征进行搜索
WP_User_Query::parse_query(). 例如,我们还可以:
$args = array (
\'post_type\' => \'any\',
\'post_status\' => \'public\',
\'_private_author_query\' => array (
\'role\' => \'editor\',
),
) ;
$posts = new WP_Query ($args) ;
等等。