LIKE
as a compare value doesn’t make sense with an array. You want compare
to be IN
. Also, you’ve got an extra set of quotes in the values
for no reason:
$meta_query_args = [
[
'key' => 'checkboxes',
'value' => ['facebook', 'twitter'],
'compare' => 'IN',
],
];
EDIT: So, according to your comment you’re using ACF, which stores multiple checkboxes as a serialized array. Therefore you need to use multiple LIKE queries on individual strings.
$meta_query_args = [
'relation' => 'OR',
[
'key' => 'checkboxes',
'value' => '"facebook"',
'compare' => 'LIKE',
],
[
'key' => 'checkboxes',
'value' => '"twitter"',
'compare' => 'LIKE',
],
];
Your mistake was trying to use an array as a value with LIKE. To query LIKE multiple possible values you need multiple meta queries with the OR
relation. The extra quotes are because it’s the only way to really query a specific value within a serialized array.
The meta value for checkboxes
if Facebook and Twitter were checked would look something like this:
a:2:{i:0;s:8:"facebook";i:1;s:7:"twitter";}
So when you query LIKE
'"facebook"
you’re trying to find the value "facebook"
within a full value like that. The quotes are to make sure you don’t incorrectly find a value like not_facebook
.
If you have a lot of values that you need to query this way then your performance is going to be awful. This is a very inefficient way to store data for this type of query.