WP_Query – Order results by meta value

I’ve checked around and haven’t seen an answer which works as of yet. I have a WP_Query with the following arguments:

$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'
);

2

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

Leave a Comment