I’m working on a form for filtering a list of posts using custom fields created with the Advanced Custom Fields plugin. Because of the form, I’m using the pre_get_posts
action to change the query via GET requests. (following code references are either PHP or dumped from print_r()
)
I set the meta_query like this:
$query->set('meta_query',$filter);
and $filter
looks like this:
Array
(
[0] => Array
(
[key] => delivery_method
[value] => Array
(
[0] => Online
[1] => Scheduled
)
[compare] => IN
)
)
The custom field that I am querying is structured like this:
Array (
[delivery_method] => Array (
[0] => Online
[1] => Scheduled
)
)
When I look for posts with [compare] => IN
(as above), no posts are returned. When I look for posts with [compare] => NOT IN
, all of the posts are returned.
I am trying to return only those posts which have a specific “delivery method”. Is there a way to compare the two arrays that I missed? or do I have to somehow explode one of the arrays and compare individual values against an array?