0

I have a custom post type "car". I've created a loop to show all the titles of that post type. I want to show them alphabetically. But the order is ignored.

<?php
$loop = new WP_Query( array(
    'post_type' => 'car',
    'orderby' => 'title',
    'order' => 'DESC'
)
);
while ( $loop->have_posts() ) : $loop->the_post();

the_title();

endwhile; wp_reset_query(); 
?>

The order output is the same order of the input. So I've added Volkswagen Tiguan first, so that is shown first and not Audi A1 (for example).

1
  • 1
    order should be ASC if you want them displayed alphabetically. i.e. (1, 2, 3, a, b, c, d)
    – Den Isahac
    Nov 27, 2020 at 8:18

1 Answer 1

-1

quick info, use this to know what is being return:

$loop = new WP_Query( array(
    'post_type' => 'car',
    'orderby' => 'title',
    'order' => 'asc'
)
);
echo '<pre>';
print_r($loop);

wp_reset_postdata();

Also I believe is better at the end reset the postdata to be sure that nothing is being change in the database. For all I had read this is good to use everytime we open a new WP_Query.

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.