I have a custom date
field that is optional. If a date is not provided, the item should be first in the items returned by WP_Query
. Example:
1st: entry with no date
2nd: entry with date 1 March 2023
3rd: entry with date 1 February 2023
4th: entry with date 1 January 2023
These are the args I'm using:
'meta_key' => 'custom_date',
'orderby' => array(
'date_empty' => 'ASC',
'custom_date' => 'DESC'
),
'meta_query' => array(
'relation' => 'OR',
'date_empty' => array(
'key' => 'custom_date',
'value' => '',
'compare' => '='
),
'date_not_empty' => array(
'key' => 'custom_date',
'value' => '',
'compare' => '!='
)
),
However the order is showing with the dates in the wrong order:
1st: entry with no date
2nd: entry with date 1 January 2023
3rd: entry with date 1 February 2023
4th: entry with date 1 March 2023
It seems the second orderby
clause is having no impact. I have checked that the date clause works fine when I remove the first clause.