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've searched the web to try and do this but none of the examples quite resemble the way my data is currently laid out, I wonder if someone can tell me how to tailor it to my setup?

This is the way it's currently pulling in my posts:

'meta_key' => 'matchdate',
    'orderby' => 'meta_value',
    'order' => 'DESC',
    'meta_query' => array(
            array (
            'key' => 'matchdate',
            'meta_value' => mktime(0,0,0,date("n"),date("j"),date('Y')),
            'type' => 'NUMERIC',
            'compare' => '>=',  

Etc. This sorts a load of football matches by a custom post meta of "matchdate" which stores the date of a match as a unix timestamp and converts it as it displays.

However, for matches on the same day there are then sorted by alphabetical order, which is not what I want. There is another (simple numeric) field that stores kickoff times as "kickoff" as "15:00", "12:45", "17:00" etc. What I'd like to do is sort the matches firstly by matchdate, with the most recent first (as it currently does) but then by kickoff times, also with the most recent first (so 17:30 would appear above 15:00 for matches with the same date).

Any help would be HUGELY appreciated! The problem with the existing code is that I copied bits of it from different places so I don't have a full understanding of how it works.

Thanks :)


share|improve this question

Why don't store date and kickoff time in the same datetime field and sort it by this meta value?

Please, note that you may need change this:

$args = array(
        'orderby' => 'meta_value',


$args = array(
        'orderby' => 'meta_value_num',
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.