Use a nested meta query when querying by role in WP_User_Query.

If a user query includes a meta query together with a role argument,
nest the original meta query and append the role meta query with an
AND relationship.

fixes #23849, #27026.


git-svn-id: https://develop.svn.wordpress.org/trunk@30094 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Konstantin Kovshenin
2014-10-29 21:40:04 +00:00
parent 555d7347f9
commit 6debe759a6
2 changed files with 42 additions and 5 deletions

View File

@@ -221,4 +221,33 @@ class Tests_User_Query extends WP_UnitTestCase {
$query->prepare_query();
$this->assertEquals( $_query_vars, $query->query_vars );
}
/**
* @ticket 23849
*/
function test_meta_query_with_role() {
$author_ids = $this->factory->user->create_many( 4, array( 'role' => 'author' ) );
add_user_meta( $author_ids[0], 'foo', 'bar' );
add_user_meta( $author_ids[1], 'foo', 'baz' );
// Users with foo = bar or baz restricted to the author role.
$query = new WP_User_Query( array(
'fields' => '',
'role' => 'author',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'foo',
'value' => 'bar',
),
array(
'key' => 'foo',
'value' => 'baz',
),
),
) );
$this->assertEquals( array( $author_ids[0], $author_ids[1] ), $query->get_results() );
}
}