[英]Wordpress WP_Query 'orderby' not working
My query is not ordering my posts using the orderby
parameter. 我的查询不是使用
orderby
参数来命令我的帖子。
A little background: 一点背景:
I'm within a foreach statement that loops through a custom taxonomy for "category" IDs. 我在一个foreach语句中循环通过“类别”ID的自定义分类。 while in that foreach statement, I am attempting to invoke a new WP_Query getting posts from each "category" of that foreach loop.
在那个foreach语句中,我试图调用一个新的WP_Query从该foreach循环的每个“类别”获取帖子。 My args array is as follows:
我的args数组如下:
$args = array(
'post_type' => 'wpsc-product',
'post_status' => 'publish',
'showposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'wpsc_product_category',
'field' => 'term_id',
'terms' => $cat_id,
),
array(
'taxonomy' => 'series',
'field' => 'slug',
'terms' => $series_name
)
),
'orderby' => 'title',
'order' => 'DESC'
);
$cat_id
and $series_name
are both arrays from my custom taxonomies in this post_type. $cat_id
和$series_name
都是此post_type中我的自定义分类法中的数组。
orderby
and order
are not working at all and I cannot figure this out why. orderby
和order
根本不工作,我无法弄明白为什么。
I have checked your code on my test blog. 我在测试博客上检查了你的代码。 And it works as expected.
它按预期工作。 So parameters
所以参数
'orderby' => 'title',
'order' => 'DESC'
you have set correctly. 你设置正确。
In this situation you can check SQL request. 在这种情况下,您可以检查SQL请求。
$query = new WP_Query($args);
var_dump($query->request);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.