WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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'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
up vote 31 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 '14 at 20:00
1  
Small note, if the meta_key does not exist for the post yet, the post will be ignored. – adamj Dec 2 '15 at 2:46

protected by Community Dec 2 '15 at 2:46

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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