mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-02 03:34:33 +00:00
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:
@@ -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() );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user