6

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?

8

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') – emersonthis Sep 29 '12 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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