gpt4 book ai didi

wordpress - WP_Query 具有按数组排序的 ID 数组

转载 作者:行者123 更新时间:2023-12-02 09:13:06 25 4
gpt4 key购买 nike

我有一个 ID 数组,我想通过 WP_Quey() 获取该帖子

$myarray = $ids;
$args = array( 'post__in' => $myarray);
// The Query
$the_query = new WP_Query( $args );

它,按日期对结果进行排序但我想按 $myarray 项目对其进行排序,第一个结果将是 $myarray 中的第一个 ID

最佳答案

在 WordPress 3.5 及更高版本中,您可以使用 'orderby'=>'post__in' 然后您必须编写以下内容:

$myarray = $ids;    
$args = array('post__in'=> $myarray, 'orderby'=>'post__in');
// The Query
$the_query = new WP_Query( $args );

关于wordpress - WP_Query 具有按数组排序的 ID 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22241487/

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