0

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

        ) );

    ?>
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.