WordPress Query: Combine 'in_stock' and 'sortby' Conditions for Product Filtering
///'To make both the 'in_stock' and 'sortby' conditions work together in the array, you can modify the code as follows://n//n//n/$data['meta_query'] = array(//n 'relation' => 'AND', // Add this line to specify the relation between the conditions//n array(//n 'key' => 'qqp_qty',//n 'value' => array('0'),//n 'compare' => '>',//n ),//n);//n//nif (/$value == 'sortby') {//n /$data['orderby'] = array(//n 'meta_value_num' => 'DESC',//n 'date' => 'DESC',//n );//n /$data['meta_key'] = 'qq_product_rate';//n}//n//n//nThis code adds the 'relation' => 'AND' line to the 'meta_query' array to ensure that both conditions are applied together. Additionally, if the 'sortby' value is selected, it sets the 'orderby' parameter to sort by the 'meta_value_num' (for 'qq_product_rate') in descending order, followed by the 'date' in descending order. The 'meta_key' parameter is also set to 'qq_product_rate.'//n
原文地址: https://www.cveoy.top/t/topic/qd9f 著作权归作者所有。请勿转载和采集!