0

I need to exclude the loop two post with different values in your meta key (the same). I investigating got this code that works fine if I enter only one value in value =>. But if I want to enter two values it gives me error.

$args = array(
    'cat'           => 1,
    'meta_query'    => array(
        'relation'  => 'OR',
        array(
            'key'     => 'Caja',
            'compare' => 'NOT EXISTS'
        ),
        array(
            'key'     => 'Caja',
            'value'   => array('UNO','DOS'), // Here I return an error php: Warning: trim() expects parameter 1 to be string, array given
            'compare' => '!='
        ),
    ),
);

I used this post as a reference.

Any ideas?

1
  • Your query is inherently expensive, especially the NOT EXISTS parameter, it would be significantly faster to specify what you want rather than what you don't want
    – Tom J Nowell
    Commented Feb 23, 2016 at 14:30

1 Answer 1

1

Straight from the codex

value (string|array) - Custom field value. It can be an array only when compare is 'IN', 'NOT IN', 'BETWEEN', or 'NOT BETWEEN'.

SOLUTION

Change compare' => '!=' to compare' => 'NOT IN'

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.