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).
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).
Share Improve this question asked Nov 26, 2020 at 20:18 DennisDennis 1358 bronze badges 1 |1 Answer
Reset to default -1quick 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.
order
should beASC
if you want them displayed alphabetically. i.e. (1, 2, 3, a, b, c, d) – Den Isahac Commented Nov 27, 2020 at 8:18