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 constructed this query to sort posts on the home page by a set position number in a custom field. However, I need to be able to exclude posts with the position set to '0'. Below is the code working to sort the items, but I cannot get anything to work with excluding the posts.

<?php query_posts('meta_key=home_post_id&orderby=meta_value_num&order=DESC'); ?>
share|improve this question
See @Maugly's answer - but you shouldn't be using query_posts() – Stephen Harris Oct 30 '12 at 11:29
up vote 2 down vote accepted
$args = array(
   'meta_key'   => 'home_post_id',
   'orderby'    => 'meta_value_num',
   'order'      => 'DESC',
   'meta_query' => array(
           'key'     => 'home_post_id',
           'value'   => 0,
           'compare' => '>',
           'type'    => 'numeric',

Something like this should work but I haven't tested it .)
Let me know if it works..

Reference: WP_Query - Custom Field Parameters

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.