I'm trying to sort custom posts using multiple numeric meta values but I only has success when sorting with just a single meta key.
In resume, I've two numeric meta keys pwa_score
and installs
. I need to order the results fisrt by pwa_score
and second by installs
, both in descending order.
The code bellow works like a charm for sorting by pwa_score
only.
$args = array(
'post_type' => 'apps',
'post_status' => 'public',
'posts_per_page' => 20,
'paged' => $page,
'suppress_filters' => true,
'category_name' => $slug,
'meta_key' => 'pwa_score',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
$the_query = new WP_Query( $args );
In case of trying to sort by multiple numeric meta keys using the sample bellow the results are aways incorrect. Its orders by pwa_score
first, but installs
appears to be random.
$args = array(
'post_type' => 'apps',
'post_status' => 'public',
'posts_per_page' => 1000,
'suppress_filters' => true,
'category_name' => $slug,
'order' => 'DESC',
'meta_query' => array(
'relation' => 'OR',
'pwa_score_clause' => array( 'key' => 'pwa_score', 'type' => 'numeric' ),
'installs_clause' => array( 'key' => 'installs', 'type' => 'numeric' ),
),
'orderby' => array(
'pwa_score_clause' => 'DESC',
'installs_clause' => 'DESC',
),
);
$the_query = new WP_Query( $args );
How can I proper achieve this orderby using multiple numeric keys?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744768693a4592622.html
评论列表(0条)