WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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 have my query set up like this:

$article_query = new WP_Query(array( 
             'meta_key' => 'issue', 
             'meta_value' => $post->ID , 
             'post_type' => 'article',
             'orderby' => 'order_number', 
             'order' => 'desc'

I want all the articles for an issue, sorted by the custom field 'order_number'

As it is, the order is ignored. I have read I need to set meta_key to 'order_number' to enable ordering by that key, but that filters by that key aswel, resulting in no results.

So, how to I sort by order_number?

share|improve this question

The same problem had been discussed earlier( For reference: Filter by one custom field, order by another? ). Hope this will solve your issue.

share|improve this answer

This is how your code should be:

$args = array(
            'meta_query' => array(
                    'key' => 'issue',
                    'value' => $post->ID ,
            'post_type' => 'article',
            'orderby' => 'meta_value_num',
            'meta_key' => 'order_number',
            'order' => 'DESC'
$article_query = new WP_Query( $args );


  1. Meta query must be an array
  2. Sorting by post meta needs orderby to be defined as meta_value (if the values are strings) or meta_value_num (if the values are numbers).
  3. When sorting by post meta, 'meta_key' must follow to determine which meta is the sorting key.
share|improve this answer

Your Answer


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.