I'm using WooCommerce and I'm trying to filter my products by price. My problem is that the meta_key
is only taking into account the regular price and not the sale price.
As a result if a product is on sale, the sale price is ignored by my filter and all of the products are ordered by the regular price.
Is there a way I can order my products by both the regular price and the sale price? Any help will be greatly appreciated!
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => $posts_per_page,
'taxonomy' => 'product_cat',
's' => $search_term,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_key' => '_price',
);
_regular_price
and_sales_price
meta_key and in the same_price
meta_key for sorting purpose (depending which is smaller I think). Try to investigate your database query to find problem._price
meta_key.