I am trying to query products by a category and a custom field called 'gender'. The condition output in sql always is using "OR" instead of "AND" for the gender search.
add_filter('get_meta_sql', 'filter_query', 10, 1);
$product_dis = new WP_Query(array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'relation'=>'AND',
'tax_query' => array(
'relation'=>'AND',
array(
'relation'=>'AND',
'taxonomy' => 'product_category',
'field' => 'term_id',
'terms' => array($category_id, $subcat_id)
), ),
'meta_query' => array(
'relation'=>'AND',
array(
'relation'=>'AND',
'key' => 'gender',
'value' => $gender,
'compare' => '=',
),),
) );
OUTPUT
SELECT kh_posts.* FROM kh_posts LEFT JOIN kh_term_relationships ON (kh_posts.ID = kh_term_relationships.object_id) INNER JOIN kh_postmeta ON ( kh_posts.ID = kh_postmeta.post_id ) WHERE 1=1 AND (kh_term_relationships.term_taxonomy_id IN (10,19,21) ) OR ( ( kh_postmeta.meta_key = 'gender' AND kh_postmeta.meta_value = 'male' ) ) AND kh_posts.post_type = 'product' AND ((kh_posts.post_status = 'publish')) GROUP BY kh_posts.ID ORDER BY kh_posts.menu_order ASC