根据自定义阵列位置订购帖子 [英] order post according to custom array position
本文介绍了根据自定义阵列位置订购帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据自定义提交的帖子列表.
I want to list of post according to custom filed.
这里我有 9 个帖子,有 3 个不同的位置(中间、顶部、底部)
Here i have 9 post with different 3 position (middle, top, bottom)
Post ID title position
1 Post1 Top
2 Post2 Bottom
3 Post3 Top
4 Post4 Bottom
5 Post5 Middle
6 Post6 Bottom
7 Post7 Top
8 Post8 Bottom
9 Post9 Top
10 Post10 Middle
现在我想按照这个顺序发帖
Now i want to get post according like this order
5 Post5 Middle
2 Post2 Bottom
1 Post1 Top
10 Post10 Middle
4 Post4 Bottom
3 Post3 Top
6 Post6 Bottom
7 Post7 Top
8 Post8 Bottom
9 Post9 Top
所以首先是中间、底部、顶部,所以我想要像这样的后序,中间,底部和顶部.我不想要完整的中间位置,然后是底部,然后是顶部.
So first came middle,bottom,top so i want post order like this one, middle,bottom and top. I do not want complete middle position and then bottom and then top.
我喜欢列出中间、底部、顶部的前 3 个帖子.我需要这个列表 wordpress,有人知道吗,我该怎么做这个任务
I like to list get first 3 post of middle,bottom, top.I need this listing wordpress, can any one know, how can i do this task
谢谢企业社会责任
推荐答案
您可以使用如下查询:
SELECT PostID, title, position
FROM (
SELECT PostID, title, position,
@grp := IF(@pos = position, @grp + 1,
IF(@pos := position, 1, 1)) AS grp
FROM mytable
CROSS JOIN (SELECT @grp := 0, @pos := '') AS vars
ORDER BY position, title) AS t
ORDER BY grp, FIELD(position, 'Middle', 'Bottom', 'Top')
这篇关于根据自定义阵列位置订购帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文