我的产品没有库存状态,只是库存数量。有没有办法让元查询将其值视为0或1?例如,首先是不是0的值,然后是0的值。
我现在的查询:
\'meta_query\' => array(
\'relation\' => \'AND\',
\'quantity_total\' => array(
\'key\' => \'total_quantity\',
\'type\' => \'NUMERIC\',
\'compare\' => \'EXISTS\',
),
\'price_lowest_first\' => array(
\'key\' => \'main_price\',
\'type\' => \'NUMERIC\',
\'compare\' => \'EXISTS\',
)
),
\'orderby\' => array(
\'quantity_total\' => \'DESC\',
\'price_lowest_first\' => \'ASC\'
)
EDIT:
现在,我使用了“库存”标志,下面是我的代码://sort by total quantity
if($sort !== \'4\'){
$args[\'meta_query\'][\'in_stock\'] = array(
\'key\' => \'1C_in_stock\',
\'type\' => \'NUMERIC\',
\'compare\' => \'EXISTS\'
);
$args[\'orderby\'] = array(
\'in_stock\' => \'DESC\'
);
}
//apply sort preferences to arguments
switch($sort){
#by stock status
case \'1\':
// \'1\' is default, do not want to move it to the default clause yet.
break;
#sort by price: lower first
case \'2\':
$args[\'meta_query\'][\'price_lowest_first\'] = array(
\'key\' => \'1C_price\'
\'type\' => \'NUMERIC\',
\'compare\' => \'EXISTS\'
);
$args[\'orderby\'][\'price_lowest_first\'] = \'ASC\';
break;
#sort by price:higher first
case \'3\':
$args[\'meta_query\'][\'price_highest_first\'] = array(
\'key\' => \'1C_price\',
\'type\' => \'NUMERIC\',
\'compare\' => \'EXISTS\',
);
$args[\'orderby\'][\'price_highest_first\'] = \'DESC\';
break;
#sort randomly
case \'4\':
$args[\'orderby\'] = \'rand\';
break;
}
但是否有按非零和零数量订购项目的查询?然后,按价格订购每组。