Question

I have a simple WP_Query to get a list of posts of co-author (taxonomy author) order by date, this is the query :

                $username = get_the_author_meta( 'login', $author_id );
                $args = array(
                  'post_type' => 'any',
                  'orderby' => 'date',
                  //'orderby' => 'post_date',
                  'order'   => 'DESC',
                  'tax_query' => array(
                    array(
                      'taxonomy' => 'author',
                      'field' => 'name',
                      'terms' => $username
                      )
                  )
                );
                $query = new WP_Query( $args );

The result is always a list of posts ordering by date ASC... I have already search solution over internet without success... Any idea ?

Thanks a lot

Was it helpful?

Solution

This will definitely work....It worked for me...

    $username = get_the_author_meta( 'login', $author_id );
    $args = array(
            'post_type' => 'any',
            'orderby' => 'date',
            'order'   => 'DESC',
            'suppress_filters' => true,
            'tax_query' => array(
             array(
                   'taxonomy' => 'author',
                   'field' => 'name',
                   'terms' => $username
                  )
             )
        );

$query = new WP_Query( $args );

OTHER TIPS

Adding

'suppress_filters' => true

into the $args array did sorting in the order I needed.

If you're using the Post Types Order plugin, you may need to add the following to your query args:

'ignore_custom_sort' => true,
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top