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?

  • 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, 2011 at 2:46
  • do you actually have values in the meta field post_views_count ? Feb 24, 2012 at 5:38

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.