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)

The topic ‘search a checkbox for multiple values’ is closed to new replies.