Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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'
        )
    )
);
share|improve this answer
    
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') –  SDP Sep 29 '12 at 17:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.