Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
2  
See @Maugly's answer - but you shouldn't be using query_posts() –  Stephen Harris Oct 30 '12 at 11:29

1 Answer 1

up vote 2 down vote accepted
$args = array(
   'meta_key'   => 'home_post_id',
   'orderby'    => 'meta_value_num',
   'order'      => 'DESC',
   'meta_query' => array(
       array(
           'key'     => 'home_post_id',
           'value'   => 0,
           'compare' => '>',
           'type'    => 'numeric',
       )
   )
);
query_posts($args);

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

 
discard

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.