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 custom meta field that I use for the post rating. So I want to display posts by the date and the rating, but only for the posts that have specific rating.

For example, I want to display posts with rating above 3, and in this order: by the rating (highest first), but grouped by the date (today's best rated, then yesterday's best rated, etc.).

Can I do it with WP_Query($args=array()) class?

share|improve this question
Hi and welcome! As you can see bellow, it is possible, but please research this site and the Codex before posting a Question. Well, research efforts are required in most (if not all) the sites of the Stack network. – brasofilo Jan 17 '13 at 16:18
Thanks. I was researching but couldn't find it. Then I managed to find it on Google, but s_ha_dum already posted his answer. – bosniamaj Jan 17 '13 at 16:40
up vote 0 down vote accepted

Basically, I am reading right out of the Codex page for WP_Query.

You want a meta_query similar to this with an orderby parameter with the two values you want to order by. The first is dominant.

$args = array(
    'post_type' => 'post',
    'meta_query' => array(
            'key' => 'rating',
            'value' => 3,
            'compare' => '>'
    'orderby' => 'rating post_date',
    'order' => 'DESC'
$query = new WP_Query( $args );

I don't know what your rating field is named and I don't have your posts and your ratings on my system so I can't test that. Hopefully that will get you started.

share|improve this answer
Yes, it works, I managed to find a tutorial with similar solution just before your answer. Thanks :) – bosniamaj Jan 17 '13 at 16:38

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.