php Wordpress WP_Query 'orderby' 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13459410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wordpress WP_Query 'orderby' not working
提问by Vincent Listrani
My query is not ordering my posts using the orderbyparameter.
我的查询没有使用orderby参数对我的帖子进行排序。
A little background:
一点背景:
I'm within a foreach statement that loops through a custom taxonomy for "category" IDs. while in that foreach statement, I am attempting to invoke a new WP_Query getting posts from each "category" of that foreach loop. My args array is as follows:
我在循环遍历“类别”ID 的自定义分类法的 foreach 语句中。在那个 foreach 语句中,我试图调用一个新的 WP_Query 从该 foreach 循环的每个“类别”中获取帖子。我的 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_idand $series_nameare both arrays from my custom taxonomies in this post_type.
$cat_id并且$series_name都是来自我在这个 post_type 中的自定义分类法的数组。
orderbyand orderare not working at all and I cannot figure this out why.
orderby并且order根本不工作,我无法弄清楚原因。
回答by Vladimir
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);

