[wp-hackers] Re-ordering search results

Tom Barrett tcbarrett at gmail.com
Fri Feb 22 13:24:57 UTC 2013

Thanks Nacin

I ended up solving it in 2 parts, I think.

First I built a simple custom SQL query to get post_ids (with a second,
optional query to get another list and intersect them).
Using pre_get_posts filter, I grab those post IDs to set up $wp_query
(using sortby=>post__In)
Then add 3 filters on posts_where, posts_join and posts_orderby to order by
a specific taxonomy.

I am using pretty URLs for all this, and pagination is an issue now.
WordPress recognises the page numbers enough not to have them leak into the
other query vars. But page/paged wont populate nicely. Perhaps I should
start a new thread for that.


On 20 November 2012 14:39, Andrew Nacin <wp at andrewnacin.com> wrote:

> On Tue, Nov 20, 2012 at 8:44 AM, Tom Barrett <tcbarrett at gmail.com> wrote:
> > I have a list of companies on a site, their profiles are stored as a
> custom
> > post type and they have several levels of membership (e.g. free, bronze,
> > silver, gold). Their membership is handled with a taxonomy. I want the
> free
> > text search to prioritise gold-package search results over silver (over
> > bronze, over free).
> >
> > Is there a nice hook-able way for me to do this?
> >
> > Other solutions are to:
> >  a) perform multiple searches (ew?)
> >  b) loop several times over search result?
> >  c) loop once and build my own set of results.
> >
> > My thinking is that a simpler db query with lots of results would be
> better
> > than 4 more complex queries (but I will need the taxonomy term at some
> > point). So I either need to hook into pre_get_posts or loop through
> > $wp_query->posts?
> You can re-order $wp_query->posts on your own, but that will only be
> sufficient
> if you aren't using any pagination here. You may also want to look into how
> we
> may implement smarter ordering in core in the future (possibly 3.6) —
> http://core.trac.wordpress.org/ticket/7394. This is possible with the
> existing
> search and orderby filters.
> Nacin
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

http://www.tcbarrett.com | http://gplus.to/tcbarrett |

More information about the wp-hackers mailing list