这是我目前WP_Query的参数:
array(5) {
["posts_per_page"]=>
int(6)
["orderby"]=>
array(2) {
["uss_product_price"]=>
string(3) "ASC"
["uss_product_weight"]=>
string(4) "DESC"
}
["meta_query"]=>
array(3) {
["relation"]=>
string(3) "AND"
["sortprimary_clause"]=>
array(2) {
["key"]=>
string(17) "uss_product_price"
["compare"]=>
string(6) "EXISTS"
}
["sortsecondary_clause"]=>
array(2) {
["key"]=>
string(18) "uss_product_weight"
["compare"]=>
string(6) "EXISTS"
}
}
["paged"]=>
string(1) "1"
["post_type"]=>
string(7) "product"
}
这种新的orderby在WordPress 4.0和4.2中引入: https://make.wordpress.org/core/2014/08/29/a-more-powerful-order-by-in-wordpress-4-0/ https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/
查询基本上有效,但产品按字符串值uss_product_price和uss_product_weight排序。以前这个问题是通过在WP_Query中给meta_value_num而不是meta_value来解决的: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
我希望结果按uss_product_price(first)和uss_product_weight(second)的数值排序。如何在仍使用多个orderby参数的复杂性时告诉查询使用数值?
答案 0 :(得分:0)
答案很简单 - 添加'输入' => '数字'到元查询。
{{1}}