meta_query ‘compare’ => ‘IN’ not working

There’s no easy way to search serialized values in a meta query. If the list of values isn’t crazy long, potentially you could set up multiple meta queries:

'meta_query'    => array(
    'relation' => 'OR',
    array(
        'key'       => 'system_power_supply',
        'value'     => 'single',
        'compare'   => 'LIKE',
    ),
    array(
        'key'       => 'system_power_supply',
        'value'     => 'redundant',
        'compare'   => 'LIKE',
    )
)

Or if you wanted to get super fancy, you could set it up dynamically:

$values_to_search = array('single', 'redundant');
$meta_query = array('relation' => 'OR');
foreach ($values_to_search as $value) {
    $meta_query[] = array(
        'key'       => 'system_power_supply',
        'value'     => $value,
        'compare'   => 'LIKE',
    );
}

Leave a Comment