I have two keys, key1 and key 2, which sometimes don't exist.
I would like that :
- the posts which have a key 1 are classified according to the key 1,
- the posts which have a key 1 and a key 2 are classified according to key 1,
- the posts which do not have a key 1 but a key 2 are classified according to key 2,
- and after posts that do not have a key.
Here is one of the tests, but which did not give the expected result:
$query = new WP_Query([
'meta_query' => [
'relation' => 'OR',
['key' => 'key1', 'compare' => 'EXISTS'],
['key' => 'key1', 'compare' => 'NOT EXISTS'],
['key' => 'key2', 'compare' => 'EXISTS'],
['key' => 'key2', 'compare' => 'NOT EXISTS'],
],
'order' => 'DESC',
'orderby' => 'meta_value_num',
]);
Do you know how to do it ?
question from:https://stackoverflow.com/questions/65540735/query-with-multiple-key-and-conditions