admin管理员组文章数量:1427301
I am trying to get posts in Ascending order using WP_Query,
$args = array(
'date_query' => array(
array(
'year' => $ppy,
'orderby' => 'post_date',
'order' => 'ASC',
),
),
);
$query = new WP_Query( $args );
But I am getting posts in descending order, I var_dumped the query and noticed that order is still DESC,
[request] => SELECT SQL_CALC_FOUND_ROWS wpqk_posts.ID FROM wpqk_posts WHERE 1=1 AND ( YEAR( wpqk_posts.post_date ) = 2017 ) AND wpqk_posts.post_type = 'post' AND ( wpqk_posts.post_status = 'publish' OR wpqk_posts.post_status = 'acf-disabled' OR wpqk_posts.post_status = 'private' ) ORDER BY wpqk_posts.post_date DESC LIMIT 0, 10
I am trying to get posts in Ascending order using WP_Query,
$args = array(
'date_query' => array(
array(
'year' => $ppy,
'orderby' => 'post_date',
'order' => 'ASC',
),
),
);
$query = new WP_Query( $args );
But I am getting posts in descending order, I var_dumped the query and noticed that order is still DESC,
Share Improve this question edited May 25, 2019 at 21:01 admcfajn 1,3262 gold badges13 silver badges30 bronze badges asked Jul 4, 2017 at 22:04 Abdul WaheedAbdul Waheed 131 silver badge3 bronze badges[request] => SELECT SQL_CALC_FOUND_ROWS wpqk_posts.ID FROM wpqk_posts WHERE 1=1 AND ( YEAR( wpqk_posts.post_date ) = 2017 ) AND wpqk_posts.post_type = 'post' AND ( wpqk_posts.post_status = 'publish' OR wpqk_posts.post_status = 'acf-disabled' OR wpqk_posts.post_status = 'private' ) ORDER BY wpqk_posts.post_date DESC LIMIT 0, 10
1 Answer
Reset to default 1You've made "orderby" and "order" part of the date_query sub-array. "Order" parameters belong to the main parameters array.
I can't vouch for the part of your code that concerns the year and the above-undefined variable $ppy, but if you want the posts from a specified year in ascending order by 'post_date' (which is the default), you'd try:
$args = array(
'date_query' => array(
'year' => $ppy,
),
'order' => 'ASC',
);
You can leave off 'post_date', since it's the default, but it doesn't hurt to specify if you've got a lot else going on that may potentially change the query.
本文标签: wp queryOrderby ASC changes to DESC in WPQuery
版权声明:本文标题:wp query - Orderby ASC changes to DESC in WP_Query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745464095a2659454.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论