The meta_query
parameter will actually be transformed into a WP_Meta_Query
object, and the relation verification won’t go deeper in wp-includes/meta.php
, and occurs just once in the top level:
1 2 3 4 5 | if ( isset( $meta_query['relation'] ) && strtoupper( $meta_query['relation'] ) == 'OR' ) { $this->relation = 'OR'; } else { $this->relation = 'AND'; } |
A possible solution for this is to build your own JOIN for this query.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | $query = new WP_Query( array( ... 'my_meta_query' => true, 'suppress_filters' => false ) ); add_filter( 'posts_join', 'my_meta_query_posts_join', 10, 2 ); function my_meta_query_posts_join( $join, $query ) { if ( empty( $query->query_vars['my_meta_query'] ) ) return $join; global $wpdb; $new_join = " INNER JOIN {$wpdb->postmeta} pm1 ON 1=1 AND pm1.post_id = {$wpdb->posts}.ID AND pm1.meta_key = '_some_meta_key' AND pm1.meta_value = 'some_value' "; return $join . ' ' . $new_join; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.