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 am using wp-postviews plugin to to track views of my post The author provided a query to order post by views in index.php

 <?php query_posts('v_sortby=views&amp;v_orderby=desc') ?>

But when I am using the same key with diff query it isn't working This is my code to get post with less than 22 views

 <?php query = new WP_Query( array( 'meta_key' => 'views', 'orderby' => 'desc', 'meta_value'  => '22', 'meta_compare' => '<=', 'post_type' => 'post' ) );
share|improve this question

1 Answer 1

While comparing numbers in meta value use "meta_value_num" instead of "meta_value"

'meta_value_num' - Order by numeric meta value (available with Version 2.8). Also note that a 'meta_key=keyname' must also be present in the query. This value allows for numerical sorting as noted above in 'meta_value'.

Reference

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.