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'm using query_posts to sort order certain categories. My code look like this:


This does show post in exact sorting model as I specify. However, query above doesn't display that post doesn't have meta_key 'field_ordering' set in database.

My problem is, I don't want to set it on ALL post, but I still can display the data.

Any solutions?

share|improve this question
up vote 2 down vote accepted

Well, you can't sort by field that isn't there. You can modify query conditionally only in those categories which have that field and let default query work in rest.

It would be something like:

if( is_category('abs') )
    array('orderby' => 'meta_value', 
                  'meta_key' => 'field_order', 
                  'order' => 'Desc' ),
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.