Meta Query querrying several post types based on ACF fields is broken after update to WP 4.1

The problem is with the arg 'meta_key' => 'meta_value'meta_key isn’t needed if you have a meta_query arg (despite what the codex appears to say) and its value here doesn’t make sense anyway – so just remove it.

However it does point out a behavioural change in 4.1 as before the meta_key was ORed with the meta_query keys (hence your query worked as the meta_key = 'meta_value' clause was basically a no-op) but now it’s ANDed and so fails. WP 4.0.1:

wp_postmeta.meta_key = 'meta_value' OR wp_postmeta.meta_key = 'field1_0_subfield' OR wp_postmeta.meta_key = 'field2' ...

WP 4.1 (mt1 being an alias of wp_postmeta):

wp_postmeta.meta_key = 'meta_value' AND (mt1.meta_key = 'field1_0_subfield' OR mt1.meta_key = 'field2' ...)

(PS an easy way to see what SQL is being produced by a query is to look at $query->request.)

Leave a Comment