Each of my posts (online store items) has meta keys:
tdlrm_mp
- my own menu_position (goes from 1 up and, unlike the wp_posts menu_position, may not exist)1C_quantity_total
- number of items in stock
I'd like the items to be output in the following order:
- first, the ones where
tdlrm_mp
exists, ordered bytdlrm_mp
lowest to highest - then, the ones where
tdlrm_mp
does not exist, ordered by1C_quantity_total
, highest to lowest
Here are the arguments for my meta query:
$args['meta_query'] = array(
'tdlrm_mp_key' => array(
'relation' => 'OR',
'tdlrm_mp_exists' => array(
'key' => 'tdlrm_mp',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
'tdlrm_mp_not_exists' => array(
'key' => 'tdlrm_mp',
'compare' => 'NOT EXISTS',
)
),
'quantity_total' => array(
'key' => '1C_quantity_total',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
);
$args['orderby'] = array(
'tdlrm_mp_key' => 'ASC',
'quantity_total' => 'DESC'
);
This doesn't seem to work, the posts get ordered by quantity only. What am I doing wrong here?
I tried plain
$args['orderby'] = array(
'tdlrm_mp' => 'ASC',
'1C_quantity_total' => 'DESC',
);
But it first outputs the items where tdlrm_mp
does not exist
I've also found this question , but can't figure out if it applies here