10

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

1
  • 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
    Commented Nov 10, 2016 at 10:31

3 Answers 3

16

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 );
2
  • 1
    Is not working for me..
    – Radmation
    Commented Nov 20, 2017 at 19:08
  • add this one in the args 'suppress_filters' => true, Commented Feb 27, 2020 at 5:23
3

Adding

'suppress_filters' => true

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

2
  • 3
    This is an indication that a plugin or theme hook is modifying the query.
    – Howdy_McGee
    Commented Feb 15, 2018 at 22:02
  • 1
    Check if you have Post Types Order plugin installed or any other plugin disable it. then query works fine Commented Aug 17, 2020 at 17:37
1

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

'ignore_custom_sort' => true,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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