I have very complex meta query that breaks into two part. Each part working fine alone but when I compare both part with or it should show me combination of both result(s), but its not showing anything.
First snippet
array(
'relation' => 'AND',
array(
'relation' => 'AND',
array(
'key' => 'range1_min',
'value' => floatval($_GET['m']),
'type' => 'DECIMAL',
'compare' => '<='
),
array(
'key' => 'range1_max',
'value' => floatval($_GET['m']),
'type' => 'DECIMAL',
'compare' => '>='
)
),
array(
'relation' => 'AND',
array(
'key' => 'range1_min',
'value' => floatval($_GET['n']),
'type' => 'DECIMAL',
'compare' => '<='
),
array(
'key' => 'range1_max',
'value' => floatval($_GET['n']),
'type' => 'DECIMAL',
'compare' => '>='
)
)
);
Second snippet
array(
'relation' => 'AND',
array(
'relation' => 'AND',
array(
'key' => 'range2_min',
'value' => floatval($_GET['m']),
'type' => 'DECIMAL',
'compare' => '<='
),
array(
'key' => 'range2_max',
'value' => floatval($_GET['m']),
'type' => 'DECIMAL',
'compare' => '>='
)
),
array(
'relation' => 'AND',
array(
'key' => 'range2_min',
'value' => floatval($_GET['n']),
'type' => 'DECIMAL',
'compare' => '<='
),
array(
'key' => 'range2_max',
'value' => floatval($_GET['n']),
'type' => 'DECIMAL',
'compare' => '>='
)
)
);
Individually they both are working fine, but when I put them together with “OR” condition they are not working.
Full code snippet
array(
'relation' => 'OR',
array(
'relation' => 'AND',
array(
'relation' => 'AND',
array(
'key' => 'range1_min',
'value' => floatval($_GET['m']),
'type' => 'DECIMAL',
'compare' => '<='
),
array(
'key' => 'range1_max',
'value' => floatval($_GET['m']),
'type' => 'DECIMAL',
'compare' => '>='
)
),
array(
'relation' => 'AND',
array(
'key' => 'range1_min',
'value' => floatval($_GET['n']),
'type' => 'DECIMAL',
'compare' => '<='
),
array(
'key' => 'range1_max',
'value' => floatval($_GET['n']),
'type' => 'DECIMAL',
'compare' => '>='
)
)
) ,
array(
'relation' => 'AND',
array(
'relation' => 'AND',
array(
'key' => 'range2_min',
'value' => floatval($_GET['m']),
'type' => 'DECIMAL',
'compare' => '<='
),
array(
'key' => 'range2_max',
'value' => floatval($_GET['m']),
'type' => 'DECIMAL',
'compare' => '>='
)
),
array(
'relation' => 'AND',
array(
'key' => 'range2_min',
'value' => floatval($_GET['n']),
'type' => 'DECIMAL',
'compare' => '<='
),
array(
'key' => 'range2_max',
'value' => floatval($_GET['n']),
'type' => 'DECIMAL',
'compare' => '>='
)
)
)
);
Any help would be greatly appreciated.
When I generate sql query of wordpress and run it on phpmyadmin, it generate error and saying that I have exceeded default join setting, means in my query I have too many join.
I have resolve this error by manually put this sql query before my wordpress query.