wp query – Why sorting posts doesn’t work properly?

Question

I tried a lot of methods to sort posts while getting via query but it always fails if I use DESC:

enter image description here

My code:

   <?php 
        // the query

        $args = array(               
            'orderby' => array(
                'post_date' => 'DESC',
            )
        );

        // The Query
        $the_query = new WP_Query( $args );
        
        // The Loop
        if ( $the_query->have_posts() ) {
            echo '<ul>';
            while ( $the_query->have_posts() ) {
                $the_query->the_post();
                echo '<li>' . get_the_title() . '<br>' . get_the_date().'</li>';
            }
            echo '</ul>';
        } else {
            // no posts found
        }
        /* Restore original Post Data */
        wp_reset_postdata();
        
   ?>

Also if I order them by ASC, the order will be correct, however DESC doesn’t work. What I’m doing wrong?

0
J. Wick 5 months 2021-07-10T18:56:31-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse