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've checked around and haven't seen an answer which works as of yet. I have a WP_Query with the following arguements:

$args = array(
    'post_status' => 'publish',
    'post_type' => 'listing',
    'meta_key' => 'client_feedback_score',
    'orderby' => 'client_feedback_score',
    'order' => 'DESC'
        );

$query = new WP_Query($args);

I want to order the results by the custom post field 'client_feedback_score', lowest to highest. But this doesn't seem to work... can anyone point me in the right direction?

EDIT (SOLVED):

Thanks to Milo's response, here's the working code for ordering by a numerical meta value:

$args = array(
            'post_status' => 'publish',
            'post_type' => 'listing',
            'meta_key' => 'client_feedback_score',
            'orderby' => 'meta_value_num',
            'order' => 'DESC'
        );
share|improve this question

1 Answer 1

up vote 17 down vote accepted

orderby should be meta_value_num, or meta_value, not the name of the key. See WP_Query orderby parameters.

share|improve this answer
    
Worked a treat, cheers mate. –  Adam Moss Oct 4 '11 at 15:41
    
Thanks! You're my timesaver! Nowhere on WPCodex isn't mentioned about 'meta_value_num'. –  BasTaller Jun 21 '12 at 14:04
    
+1 This worked for me too! Thanks Milo –  Scott B Jan 5 at 20:00

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.