• Resolved Marc Serra

    (@elseudomini)


    Hi to all!

    I’ve got this query:

    $args = array('category_name' => 'test','posts_per_page' => -1,'relation' => 'AND',
           'meta_query'    => array('relation'      => 'AND',
                   array(
                           'key'       => 'tipus',
                           'value'     => 'music',
                           'compare'   => 'LIKE'
                   ), ...
           )
    );

    Ok, work’s!

    But if I change 'music'for array('music') and 'LIKE' for 'IN'

    $args = array('category_name' => 'test','posts_per_page' => -1,'relation' => 'AND',
           'meta_query'    => array('relation'      => 'AND',
                   array(
                           'key'       => 'tipus',
                           'value'     => array('music'),
                           'compare'   => 'IN'
                   ), ...
           )
    );

    Doesn’t work! :_(

    What I’m missing?

    Thank’s

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Marc Serra

    (@elseudomini)

    Ok, I missed to say, that I’m using ACF anb “tipus” i a multiple select.

    Seems this query works …

    $values = array('music');
    $meta_query_or = array('relation' => 'OR');

    foreach ($values as $value) {
       $meta_query_or[] = array(
           'key'     => 'tipus',
           'value'   => $value,
           'compare' => 'LIKE'
       );
    }

    $args = array(
       'category_name' => 'test',
       'posts_per_page' => -1,
       'meta_query'    => array(
           'relation' => 'AND',
           $meta_query_or, ...
       )
    );

    Moderator threadi

    (@threadi)

    ‘IN’ checks against the key, not the value. See: https://github.com/WordPress/wordpress-develop/blob/6.7/src/wp-includes/class-wp-meta-query.php#L677

    I think you are rather looking for ‘LIKE’ for your use case.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘meta_query with array in value not working’ is closed to new replies.