我已在下面添加了查询。我要按两件事订购这些帖子,一个日期和一个美元金额。
除一个小错误外,这两种排序机制似乎都在起作用。十亿美元的美元数量出现在数百万美元的数量下降之后。
$args = array(
'post_type' => 'trecord',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'businesssector',
'terms' => $post_slug,
'field' => 'slug',
)
),
'meta_query' => array(
'relation' => 'AND',
'tombstone_year' => array(
'key' => 'mandate',
'type' => 'NUMERIC',
'compare' => 'EXISTS'
),
'tombstone_size' => array(
'key' => 'size',
'compare' => 'EXISTS',
'type' => 'NUMERIC'
),
),
'orderby' => array(
'tombstone_year' => 'DESC',
'tombstone_size' => 'DESC',
),
);
这是SQL转储。因此,我可以看到美元金额已按签名转换,因此应该可以进行排序。
SELECT wp_posts.* FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id ) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (28) ) AND ( wp_postmeta.meta_key = 'mandate' AND mt1.meta_key = 'size' ) AND wp_posts.post_type = 'trecord' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY CAST(wp_postmeta.meta_value AS SIGNED) DESC, CAST(mt1.meta_value AS SIGNED) DESC