WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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(
                'orderby' => 'meta_value',
                'meta_key' => 'regular_price',
                'order' => 'ASC',
                'paged' => $paged,
                'post_type' => 'product',
                'tax_query' => array(
                    'relation' => 'AND',
                        'taxonomy' => 'pa_width',
                        'field' => 'slug',
                        'terms' => $width),
                        'taxonomy' => 'pa_aratio',
                        'field' => 'slug',
                        'terms' => $aratio),
                        '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

share|improve this question
up vote 0 down vote accepted

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 use meta_value_num instead. You can read more in here: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

share|improve this answer
David - Thanks for that - works like a charm. Much appreciated. – Amit Wadhwa Feb 21 '13 at 12:37
You're welcome. Would you mark answer as correct than, please? ;) – david.binda Feb 21 '13 at 12:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.