Support

Account

Home Forums General Issues search a checkbox for multiple values

Solved

search a checkbox for multiple values

  • I want to search a checkbox for multiple values.

    This page explains how to search for a value, but only one value (red).
    https://www.advancedcustomfields.com/resources/checkbox/

    $posts = get_posts(array(
        'meta_query' => array(
            array(
                'key'     => 'colors',
                'value'   => 'red',
                'compare' => 'LIKE'
            )
        )
    ));

    How can I search for multiple Values?

    This is not working:

    $posts = get_posts(array(
        'meta_query' => array(
            array(
                'key'     => 'colors',
                'value'   => array('red', 'green', 'blue'),
                'compare' => 'LIKE'
            )
        )
    ));

    ‘compare’ => ‘IN’ is also not working.

  • 
    $posts = get_posts(array(
        'meta_query' => array(
            'relation' => 'OR',
            array(
                'key'     => 'colors',
                'value'   => 'red',
                'compare' => 'LIKE'
            ),
            array(
                'key'     => 'colors',
                'value'   => 'green',
                'compare' => 'LIKE'
            ),
            array(
                'key'     => 'colors',
                'value'   => 'blue',
                'compare' => 'LIKE'
            )
        )
    ));
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.