Meta Query “IN” doesn’t work with ACF checkbox filter

Checkbox field is stored as serialized array, therefore you can not use the IN operator and array with the values you are looking for.

To get posts with checked “melbourne”, change meta_query to:

$meta_query = array(
    array(
        'key'      => $name,
        'value'    => '"melbourne"',
        'compare'  => 'LIKE',
    )
);

To get posts with melbourne or sydney:

$meta_query = array(
    'relation' => 'OR',
    [
        'key'      => $name,
        'value'    => '"melbourne"',
        'compare'  => 'LIKE',
    ],
    [
        'key'      => $name,
        'value'    => '"sydney"',
        'compare'  => 'LIKE',
    ],
);

Think about changing the solution, because these types of queries negatively affect performance.

Leave a Comment