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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745464095a4628838.html
评论列表(0条)