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 this query:

  $new = new WP_Query(array('post_type'=>'support','order'=>'DESC', 'meta_key'=>'post_views_count', 'orderby'=> 'meta_value_num', 'posts_per_page'=>'20'));

the result set is pulling the correct number of posts, from the custom post type support but the posts are not ordered by the meta_value.

I cannot fathom why this is as the codex shows this is the correct way to order by a custom meta value?

share|improve this question
Seems like the code is right...what does var_dump($new) give you? Are you sure the spelling on your meta_key is correct? – tollmanz Jul 19 '11 at 2:46
do you actually have values in the meta field post_views_count ? – helgatheviking Feb 24 '12 at 5:38

I had trouble with a similar issue of sorting posts from a custom post type in a specified order on their archive page. I used http://wordpress.org/extend/plugins/sort-query-posts/.

The plugin lets you sort posts by author, comment_count, date, id, menu_order, modified, parent, or title. It only requires you to add the following lines

<?php query_posts(array('post_type'=>'post_type_name', 'posts_per_page' => 20)); ?>
<?php sort_query_posts_by('sort_type', 'order'); ?>

to your code, before the loop. Where 'sort_type' is the item by which your posts are sorted and 'order' is asc, desc, or rand. (very clear instructions in the short readme file).

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.