From 1df3af081cc816d3add904e4b7eb8dad6de1c8c7 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 14 Dec 2017 14:17:20 +0000 Subject: [PATCH] Add ID orderby fallback for when prices are the same across multiple products. --- includes/class-wc-query.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-query.php b/includes/class-wc-query.php index 53b1b96550e..504ab7685fb 100644 --- a/includes/class-wc-query.php +++ b/includes/class-wc-query.php @@ -522,7 +522,7 @@ class WC_Query { } else { $args['join'] .= " INNER JOIN ( SELECT post_id, min( meta_value+0 ) price FROM $wpdb->postmeta WHERE meta_key='_price' GROUP BY post_id ) as price_query ON $wpdb->posts.ID = price_query.post_id "; } - $args['orderby'] = ' price_query.price ASC '; + $args['orderby'] = " price_query.price ASC, $wpdb->posts.ID ASC "; return $args; } @@ -552,7 +552,7 @@ class WC_Query { $args['join'] .= " INNER JOIN ( SELECT post_id, max( meta_value+0 ) price FROM $wpdb->postmeta WHERE meta_key='_price' GROUP BY post_id ) as price_query ON $wpdb->posts.ID = price_query.post_id "; } - $args['orderby'] = ' price_query.price DESC '; + $args['orderby'] = " price_query.price DESC, $wpdb->posts.ID DESC "; return $args; }