6

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

  • 2
    You want to order by date with DESC order ? Maybe you've a plugin or the theme interfering with the query? What happens if you use 'suppress_filters' => true ? – birgire Nov 10 '16 at 10:31
6

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 );
  • Is not working for me.. – Radmation Nov 20 '17 at 19:08
1

Adding

'suppress_filters' => true

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

  • 2
    This is an indication that a plugin or theme hook is modifying the query. – Howdy_McGee Feb 15 '18 at 22:02

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.