gpt4 book ai didi

php - 如何使用 WP_Query 对 post_IDs 键而不是值进行排序

转载 作者:太空宇宙 更新时间:2023-11-03 11:56:00 25 4
gpt4 key购买 nike

我像这样将 post_ids 传递给 WP_Query()

$result_post_ids = $wpdb->get_results("SELECT  DISTINCT auction_id 
FROM " . $wpdb->prefix . "simple_auction_log
WHERE userid = $user_id
order by date DESC" , ARRAY_N);

$args = array (
'post__in' => $result_post_ids ,
'post_type' => 'product' ,
'posts_per_page' => $limit ,
'paged' => $page ,
'tax_query' => $category_filter , //category
'orderby' => $order_by,
'order' => $order
);

$result_post_ids 数组是这样的

array (size=15)
0 => string '175' (length=3)
1 => string '148' (length=3)
2 => string '169' (length=3)
3 => string '176' (length=3)
4 => string '170' (length=3)
5 => string '205' (length=3)
6 => string '142' (length=3)
7 => string '168' (length=3)
8 => string '132' (length=3)
9 => string '173' (length=3)
10 => string '177' (length=3)
11 => string '84' (length=2)
12 => string '171' (length=3)
13 => string '128' (length=3)
14 => string '82' (length=2)

所以这是我想查看的 id 的顺序,但是当将 $args 传递给 WP_Query() 时,会根据值重新排序帖子 id,因此他首先像这样显示具有磨碎器值的帖子

 177 , 176 , ...

但我想按键 0、1、2 的顺序显示,请提前提供帮助,非常感谢。

最佳答案

您应该将orderby 参数更改为post__in:

$args = array (
'post__in' => $result_post_ids ,
'post_type' => 'product' ,
'posts_per_page' => $limit ,
'paged' => $page ,
'tax_query' => $category_filter ,
'orderby' => 'post__in', // Order by the array passed in above
'order' => $order
);

来自 the Codex :

'post__in' - Preserve post ID order given in the post__in array (available since Version 3.5)

关于php - 如何使用 WP_Query 对 post_IDs 键而不是值进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32588602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com