Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.