In the codex it says its possible to do get_users() with multiple meta keys by using the meta_query parameter but it doesn't explain how. Can someone give me an example?
1 Answer
As it mentions in the Codex page for get_users
, it works the same as a WP_Query
meta_query
, see that page for full arguments list and examples.
$args = array(
'meta_query' => array(
array(
'key' => 'some_key',
'value' => 'foo',
'compare' => '='
),
array(
'key' => 'another_key',
'value' => array( 'bar', 'baz' )
'compare' => 'IN'
)
)
);
-
I'm having trouble getting this to work with the 'NOT EXISTS' operator as the value of
'compare'
. If I want to return all users that DON'T have a specific key, should this work?array('key'=>'some_key','compare'=>'NOT EXISTS')
Commented Sep 29, 2012 at 17:55 -
@emersonthis 10+ years later.. :) it should work. But guys be aware that when you use 2 or more query (inner)array, there is the 'relation' parameter, is set to 'AND' by default between them(in the outer array). read more --> developer.wordpress.org/reference/classes/wp_query/… Commented Dec 8, 2022 at 12:35