wordpress :: WP_QUERY 不按标题对帖子进行排序

发布于 2024-11-02 17:00:41 字数 626 浏览 0 评论 0原文

我正在使用 WP_QUERY 来获取帖子。问题是我想按标题对帖子进行排序,但出了问题。我可以得到帖子但没有排序。

我跟踪了 WP_QUERY 类,发现这是它生成的选择查询,

SELECT SQL_CALC_FOUND_ROWS wp_posts . * 
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 ( 4, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 )
)
AND wp_posts.post_type =  'ecommerce'
AND (
wp_posts.post_status =  'publish'
OR wp_posts.post_status =  'private'
)
GROUP BY wp_posts.ID
ORDER BY  `wp_posts`.`post_title` ASC 
LIMIT 0 , 10

很明显它是按帖子标题正确排序的,但我不确定问题是什么,

有什么帮助吗?

谢谢

i'm using WP_QUERY to get posts. the problem is that i want to sort the posts by title, but something is going wrong. i could get the posts but not sorted.

i traced WP_QUERY class and i found that this is the select query that it produced

SELECT SQL_CALC_FOUND_ROWS wp_posts . * 
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 ( 4, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 )
)
AND wp_posts.post_type =  'ecommerce'
AND (
wp_posts.post_status =  'publish'
OR wp_posts.post_status =  'private'
)
GROUP BY wp_posts.ID
ORDER BY  `wp_posts`.`post_title` ASC 
LIMIT 0 , 10

it's obvious that it's ordering by post title correctly, but i'm not sure what is the problem

any help ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友欢 2024-11-09 17:00:41

也许某些标题的左侧字符中有空格。你可以尝试一下:

ORDER BY  LTRIM(wp_posts.post_title) ASC

Perhaps some titles have spaces in the left characters. Can you try with:

ORDER BY  LTRIM(wp_posts.post_title) ASC
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文