0

I have custom wp query and i need to sort it according to taxonomy called 'consultation_records' which contains years 2017, 2018, 2019 etc.

I used this code but the result is the posts not ordered correctly i got for example 2021 > 2022 > 2023 > 2019 > 2017 > 2018

What i did wrong?

      <?php     $loop = new WP_Query(['post_type' => 'consultation_records',
                  'posts_per_page' => -1,
                  'orderby' => 'taxonomy',
                  'order' => 'DESC', 
                  'tax_query' => array(
                                    array(  'taxonomy' => 'consultation_year', 
                                            'field' => 'slug',
                                            'operator' => 'EXISTS',
                    ),),]);
        
        while ( $loop->have_posts() ) : $loop->the_post();

1 Answer 1

0

Changing the 'orderby' => 'taxonomy' to 'orderby' => 'term_order' should to the trick.

1
  • Still the same :/ Sep 19, 2023 at 1:00

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.