WP_User_Query with combined meta query – not working?

It looks like you’re using wrong parameters, please try this instead (untested):

$q = new WP_User_Query( 
    array(
        'role'          => 'contributor',
        'meta_query'    => array(
            'relation'  => 'AND',
            array( 
                'key'     => 'first_meta',
                'value'   => '2',
            ),
            array(
                'key'     => 'second_meta',
                'value'   => '',
                'compare' => '!='
            )
        )
    ) 
);

where we’ve used the key, value and compare parameters within the meta_query array. I’ve also removed the 'fields' => 'all' part, because it’s set by default.

Leave a Comment