Wordpress wp_query orderby not working

时间:2021-01-11 16:37:59

I am trying to get ordering working in wp_query, but posts are still being ordered with default settings (just tag__in is working). SQL query for posts looks like this:

我试图让订单在wp_query中工作,但仍然使用默认设置订购帖子(只是tag__in正在运行)。对帖子的SQL查询如下所示:

string(379) "SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (81) ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 3" 

Here is code snippet:

这是代码片段:

remove_all_filters('posts_orderby');
$tag = get_term_by('name', 'title_post', 'post_tag');
$args=array(
            'order'=>'ID',
            'orderby'=>'ASC',
            'tag__in' => $tag,
            'posts_per_page'=>3, // Number of related posts to display.
            'caller_get_posts'=>1
);

$my_query = new wp_query( $args );
var_dump($my_query->request);

Thanks!

谢谢!

2 个解决方案

#1


0  

Ok, I switched order and orderby ... So, correct arguments are 'orderby'=>'ID','order'=>'ASC',

好的,我切换了order和orderby ...所以,正确的参数是'orderby'=>'ID','order'=>'ASC',

#2


0  

I have checked your code you have to pass wrong arguments.

我检查了你的代码,你必须传递错误的参数。

Can you please check below code?

你能检查下面的代码吗?

Wrong

错误

'order'=>'ID',
'orderby'=>'ASC',

Right

'order'=>'ASC',
'orderby'=>'ID',

#1


0  

Ok, I switched order and orderby ... So, correct arguments are 'orderby'=>'ID','order'=>'ASC',

好的,我切换了order和orderby ...所以,正确的参数是'orderby'=>'ID','order'=>'ASC',

#2


0  

I have checked your code you have to pass wrong arguments.

我检查了你的代码,你必须传递错误的参数。

Can you please check below code?

你能检查下面的代码吗?

Wrong

错误

'order'=>'ID',
'orderby'=>'ASC',

Right

'order'=>'ASC',
'orderby'=>'ID',