Problem: ACF field has array of IDs (stored as strings) not obeying WPQuery (custom query)
Data of post_meta.meta_key = 'EventTopicId'
a:3:{i:0;s:2:"10";i:1;s:2:"32";i:2;s:2:"30";}
I have several other meta_key fields that, combined, create a filter for WPQuery. (e.g. EventTopicId + CategoryId + ...)
Id's are passed as array. When using 'IN' operator the query returns 0 results. This is the closest I've found to what I believe I need. Array into Comma separated array in PHP.
$metaSearchQuery[] =[
'key' => 'EventTopicId',
'value' => $eventTopicId,
'compare' => 'IN'
];
The problem is that my MetaQuery is an AND relationship (filter1 + filter2 etc). The assumption was 'IN' would do the job on ACF field... But if I pass an array of 10 $eventTopicId= ['10']; then zero results returned.
The above returns 0 results. EndDates and SessionDetails data are OK for posts I'm testing. It seems that the correct SQL would be
( mt1.meta_key = 'EventTopicId' AND ( mt1.meta_value like '"10"' OR mt1.meta_value like '"11"' ... )
How would one craft a WP search query with multiple meta_keys, some strings, some arrays.
NOTE: I've tried this to cast as string with little results
array_walk($eventTopicId, function(&$value, $key) {
return $value = '"'.$value.'"';
//return $value = (string) $value;
});
UPDATE: This raw SQL works.
So the question still remains: How can you craft an SQL like this using WPQuery and MetaData.



