LC
php
Back to Snippets

WordPress ACF Meta Query for Checkbox Fields

Query posts by ACF checkbox field values using WP_Query meta_query.

wordpressacfwp-querymeta-query
php
      $args = array(
    'post_type'  => 'product',
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key'     => 'product_features',
            'value'   => '"wireless"',
            'compare' => 'LIKE',
        ),
        array(
            'key'     => 'product_features',
            'value'   => '"bluetooth"',
            'compare' => 'LIKE',
        ),
    ),
);

$query = new WP_Query($args);

    

ACF stores checkbox values as serialized arrays. Use LIKE with the value wrapped in "quotes" to match individual checkbox values within the serialized string.