我正在尝试在 Wordpress 中为 woo-commerce 产品实现过滤和排序系统。我的系统中有两个价格(买和租)下面是参数数组:
$args = array(
"post_type" => "product",
'orderby' => 'meta_value_num',
// This is to order by price
'meta_key' => '_regular_price',
'order'=>'ASC',
'meta_query' => array(
'relation' => 'AND',
array(
// This is for getting price values greater than 1 in the ordering
'key' => '_regular_price',
'value' => 0,
'compare'=>'>'
),
array(
"relation" => 'OR',
array(
"key" => array('_regular_price','rent_price'),
"value" => array(1, 1000),
"compare" => 'BETWEEN',
"type" => 'DECIMAL'
),
array(
"key" => array('_regular_price','rent_price'),
"value" => array(5000, 10000),
"compare" => 'BETWEEN',
"type" => 'DECIMAL'
),
)
), );
如果我删除 order by 子句它可以正常工作,否则如果我删除 filter 子句它可以正常工作。但是两个一起用是不行的。
以下是我希望实施的条件:
- 按购买价格或租金价格订购(未选择价格范围且价格 > 0)
- 在价格范围(单个价格范围或多个)之间过滤产品
- 以上两者加起来