admin管理员组文章数量:1313760
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.
本文标签: phpOrder custom post type is beign ignored
版权声明:本文标题:php - Order custom post type is beign ignored 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741957813a2407090.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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