本文介绍了Order 和 OrderBy 上的 WP 查询不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码有问题,似乎我的 order/orderby 在我的 WP Query 上不起作用,当我将订单值设置为 DESC 时,当我检查 wpdb lastquery 时它仍然没有改变 ASC.
I have a problem with my code, it seems that my order/orderby is not working on my WP Query, when i set the order value to DESC, its not changing still ASC when i check on wpdb lastquery.
这是我的代码:
$args = array(
'post_status' => 'publish',
'posts_per_page' => $per_page,
'paged' => $paged,
'orderby'=> 'date',
'order'=> $sortBy,
'posts_per_page' => $per_page,
'post_type'=> 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id', //This is optional, as it defaults to 'term_id'
'terms' => $catby,
'operator' => 'IN', // Possible values are 'IN', 'NOT IN', 'AND'.
'suppress_filters' => false
)
),
'date_query' => array(
array(
'after' => $rangeby
)
)
);
但是当我使用这个简单的 args DESC 命令时:
But when i use this simple args DESC order is working:
$args = array(
'post_status' => 'publish',
'posts_per_page' => $per_page,
'paged' => $paged,
'orderby'=> 'date',
'order'=> 'desc',
'suppress_filters' => true,
'post_type'=> 'product'
);
有人可以帮我解决这个问题吗?谢谢!
Can someone help me about this? Thanks!
推荐答案
我会首先回显 $sortBy 的值,在有效的示例中,您没有使用该变量,因此它可能不会返回值 'date'.
I would start by echoing the value of $sortBy, in the example that works you're not using that variable, so it probably not returning the value 'date'.
这篇关于Order 和 OrderBy 上的 WP 查询不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!