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 have a list of products, each with a price in a custom field stored as text such as "2.50" or "5.00" and I am displaying them on the page with a custom query that sorts by the price:

    if(!$wp_query) {
        global $wp_query;
    }

    $args = array(
        'meta_key' => 'price',
        'orderby' => 'meta_value_num',
        'order' => 'ASC'
    );

    query_posts( array_merge( $args , $wp_query->query ) );

This works fine for the prices, but some prices are "POA" and I would like to show them last, however the above orders in such a way that "POA" is shown first.

Is there any way to alter this, or a quick hack I could use to sort the array afterwards and put any "POA" prices last?

share|improve this question
    
try changing 'orderby' => 'meta_value_num', to 'orderby' => 'meta_value_num meta_value', –  Bainternet Mar 13 '12 at 11:51
    
Thanks but that does not work :( –  Shaun Mar 13 '12 at 13:23
    
Aha! But the other way around does work, meta_value meta_value_num ! Thanks! Do you want to write up an answer so I can vote it up? –  Shaun Mar 13 '12 at 13:24
    
posted as an answer for people who don't read comments. –  Bainternet Mar 13 '12 at 13:26

1 Answer 1

up vote 8 down vote accepted

The OrderBy argument can take more then one parameter so the solution was to change :

'orderby' => 'meta_value_num',

to:

'orderby' => 'meta_value meta_value_num',
share|improve this answer

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.