0

I don't see that it is possible when I look at the WordPress documentation but I wanted to confirm. I want to check multiple meta values against one meta key eg:

$user_query = new WP_User_Query( array( 'meta_key' => 'user_charname', 'meta_value' => 'squarepants', 'orderby' => 'meta_value_num', 'order' => 'DESC' ));

I was hoping I could just use 'meta_value' => array('value1', 'value2') but that does not work.

I have tried this as pointed out by Jacob (modified) but it gives me what appears to be all results and isn't working as intended.

 $args = array(
    'meta_query' => array(
        array(
            'key'     => 'user_charname',
            'value'   => array('spongebob', 'mickey'),
            'compare' => '='
        )
    )
 );
$user_query = new WP_User_Query( $args );
2

1 Answer 1

1

If you just wanted to know if it's possible, then yes it is possible.

But the problem as I could see it from your edited question, is that you set the compare to = which should instead be IN.

However, you didn't actually have to set it because when you supply an array of values, the operator will default to IN.

So the correct code would be:

'meta_query' => array(
    array(
        'key'     => 'user_charname',
        'value'   => array('spongebob', 'mickey'),
        'compare' => 'IN' // use IN
    )
)
2
  • 1
    Ahhhh. Don't you just love it when something is staring you in the face and you still can't see it! Thank you! Commented Sep 21, 2021 at 11:54
  • You're welcome :)
    – Sally CJ
    Commented Sep 21, 2021 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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