WordPress query_posts order by meta-key AND date

I want to make a query_posts where I order first by the number of a custom field (Facebook Likes) and second by date. But I don’t don’t know how.

My query looks like that atm:

Read More
$social_query = array(
'meta_key' => 'facebook_likes',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'posts_per_page' => 10,
'paged' => (int) $paged
);
query_posts( $social_query );

Now the posts get ordered by the number of facebook-likes. This works fine. But if there are posts with the same number of likes they get sortet randomly and thats the problem. If there are posts with the same number of facebook-likes they should be ordered by date.

Can you help me please?

Related posts

Leave a Reply

1 comment

  1. WordPress allows you to specify more than one orderby parameter. To do this, you simply separate each parameter with a blank space. Here is how your new query should look like:

    $social_query = array(
        'meta_key' => 'facebook_likes',
        'orderby' => 'meta_value_num date',
        'order' => 'DESC',
        'posts_per_page' => 10,
        'paged' => (int) $paged
    );
    query_posts( $social_query );
    

    I’m not sure if this will result in the order that you desire, but that’s what WordPress allows you to do with it’s in-built function.