I created a custom WP query to collect products that have 3 different taxonomy values in them and sorted them by price using the following:
$my_products = new WP_Query(
array(
'orderby' => 'meta_value',
'meta_key' => 'regular_price',
'order' => 'ASC',
'paged' => $paged,
'post_type' => 'product',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'pa_width',
'field' => 'slug',
'terms' => $width),
array(
'taxonomy' => 'pa_aratio',
'field' => 'slug',
'terms' => $aratio),
array(
'taxonomy' => 'pa_dia',
'field' => 'slug',
'terms' => $dia)
)));
The query returns results and is mostly fine but some the products appear out pof place – take a look at http://www.tyrebroker.ie/your-search/?width=245&aratio=40&dia=18
I dont know how to resolve this as I have trawled through the database and product details to see what could be causing the issue.
Any suggestions – thanks
Your problem is in using as orderby value
meta_value
and thus the order is correct – from computer point of view. To get currect order from human point of view, try to usemeta_value_num
instead. You can read more in here: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters