0

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

Mike

1 Answer 1

0

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',
         .........
    );

To:

$args = array(
        .......
        'orderby' => 'meta_value_num',
         .........
    );

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.