0

我需要一个自定义查询来以特殊分类顺序显示帖子。我使用这个查询:

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 ( 13, 9, 10, 11, 12, 15, 16, 17, 504 )
)
AND wp_posts.post_type = 'goods'
AND (
wp_posts.post_status = 'publish'
)
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0 , 10

但返回的结果是自动应用的顺序,如下所示:IN (9, 10, 11, 12, 13, 15, 16, 17, 504)。我怎样才能在没有任何排序的情况下取得结果?

4

2 回答 2

0

尝试更换

ORDER BY wp_posts.post_date DESC 

ORDER BY RAND()

或完全删除

于 2013-11-08T19:11:10.963 回答
0

试试这个,这将像 (13, 9, 10, 11, 12, 15, 16, 17, 504) 分类顺序

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 ( 13, 9, 10, 11, 12, 15, 16, 17, 504 )
)
AND wp_posts.post_type = 'goods'
AND (
wp_posts.post_status = 'publish'
)
GROUP BY wp_posts.ID
ORDER BY FIELD( 13, 9, 10, 11, 12, 15, 16, 17, 504 )
LIMIT 0 , 10

场(str,str1,str2,str3,...)

于 2013-11-08T19:18:12.560 回答