gpt4 book ai didi

mysql - 如何在 query_posts 的自定义字段上添加 order by

转载 作者:行者123 更新时间:2023-11-29 12:47:11 24 4
gpt4 key购买 nike

 query_posts(array(
'post_category' => 'xyz',
'post_type' => 'abc',
'posts_per_page' =>'16',
'paged'=> $paged,
'orderby' => 'post_title',
'order' => 'ASC'
));

我想根据帖子的标题按升序对正在获取的记录进行排序。当我使用

打印结果时
echo 'query : '.$GLOBALS['wp_query']->request;

我注意到订单字段是 post_date

我已将查询粘贴到下面:

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 (7) ) AND wp_posts.post_type = 'abc' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date ASC LIMIT 0, 16

最佳答案

它应该与 get_posts() 一起使用:

$args = array(
'category' => 'xyz',
'post_type' => 'abc',
'posts_per_page' =>16,
'orderby' => 'title',
'order' => 'ASC'
);

$myposts=get_posts($args);

echo '<ul>';
foreach($myposts as $post){ setup_postdata( $post );
echo '<li>'.get_the_title().'</li>';
}
wp_reset_postdata();?>
echo '</ul>';

但我不确定 'paged'=> $paged, 是什么。

关于mysql - 如何在 query_posts 的自定义字段上添加 order by,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25278611/

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