Order posts by more than one variable (meta_key and publish date AND time)

At cascadeoc.org/results I have results sorted by a Custom Field, "event_date_results" which is the date the event happened (not the date the post was published). However, when there are multiple results from the same day, I'd like to further control post order by published date and TIME. How can I add this second orderby filter?

Here's what I have:

?php

    $query = new WP_Query( array(

        'post_type' = 'result',
        'posts_per_page' = 100,
        //'paged'          = $paged,
        'meta_key'   = 'event_date_results',
        'orderby'    = 'meta_value_num',
        'order'      = 'DESC',
        'meta_value'    = date('Ymd'),
        'meta_compare'  = '',
        'date_query'    = array(
            array(
                    'key' = 'date',
                    'value' = date('Ymd'),
                    'compare' = '', //less than
                    'type' = 'DATETIME'
                )
            ),

        ) );

    ?

Topic meta-value order wp-query Wordpress

Category Web


I found this link about "a more powerful ORDER BY in WordPress 4.0" and it led me to try this code:

        <?php

    $query = new WP_Query( array(

        'post_type' => 'result',
        'posts_per_page' => 100,
        //'paged'          => $paged,
        'meta_key'   => 'event_date_results',
        'orderby'    => array( 'meta_value_num' => 'DESC', 'post_date' => 'DESC'),
        //'order'      => 'DESC',
        'meta_value'    => date('Ymd'),
        'meta_compare'  => '<',
        'date_query'    => array(
            array(
                    'key' => 'date',
                    'value' => date('Ymd'),
                    'compare' => '<', //less than
                    'type' => 'DATETIME'
                )
            ),

        ) );

    ?>

The 'orderby' line is the only thing I changed (and I commented out the other 'DESC' line I had... which I could delete now.)

...don't mind my commented out 'paged' bit... I'm still figuring out how to paginate this as well. ;)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.