WP Query: Prioritize 'in_stock' Condition for Product Filtering
To achieve the desired result, you can modify the 'in_stock' condition in the elseif block as follows:
} elseif ($key == 'in_stock') {
if ($value) {
$meta_query[] = array(
'relation' => 'AND', // Set the relation to AND
array(
'key' => 'qqp_qty',
'value' => array('0'),
'compare' => '>'
),
array(
'key' => 'qqpd_price',
'compare' => 'EXISTS' // Only consider products with price
)
);
$keys[] = 'in_stock';
}
}
By adding an additional array to the $meta_query array, you can set the relation to AND and include the condition for qqpd_price to consider only products with a price.
Note that this assumes you have a qqpd_price custom field for products. If the field name is different, please adjust it accordingly.
原文地址: https://www.cveoy.top/t/topic/qee4 著作权归作者所有。请勿转载和采集!