1

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

1 Answer 1

0

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

2
  • David - Thanks for that - works like a charm. Much appreciated. Feb 21, 2013 at 12:37
  • You're welcome. Would you mark answer as correct than, please? ;) Feb 21, 2013 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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