WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 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

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.