#16329 closed enhancement (duplicate)
Sorting query_posts posts by the order of id's given in post__in
Reported by: | danielpataki | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 3.1 |
Component: | Query | Keywords: | orderby |
Focuses: | Cc: |
Description (last modified by )
I am trying to build a search highly customized for a website. The two things I would like to do is to make posts which have the term in their title show up first, and I am also trying to make it play nice with query_posts.
I wrote two queries, one gets all the post ID's which have the term in the post title, and the other gets the post ID's which do NOT have the term in their title, but have it in the contents. I then merge these arrays. I use the resulting array of id's in the post__in
parameter of query_posts.
This does result in the correct set of posts being returned, but I am unable to order them in the order the post ids are in the post__in
clause. This would be important, since the array of post ids is in the correct order, but query_posts rearranges the results. I have tried using "none" as the orderby, but to no avail, it just sorts the posts by ID.
It would be nice if there was an option to sort by post__in
, meaning that the order of the posts returned corresponds to the order of the posts in the post__in
clause.
Change History (4)
#3
@
14 years ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
Sorting the IDs in PHP is definitely not going to scale. I suggest you look at using UNIONs instead.
As for sorting using post__in
, this has been asked before: #13729
#4
@
14 years ago
Thanks for the link to the other ticket, that is exactly what I was looking for, excuse the duplicate post.
As for the UNIONs, achieving the desired result is not difficult, I just wanted to be able to use query_posts. Since query posts can not display items in the order they are passed I won't be able to do so.
I will try and submit a patch in the other thread :)
Please excuse the underlining, post_in has two underscores and it was converted.