[wp-hackers] Filter on one meta value and sort by another

Simon Blackbourn piemanek at gmail.com
Tue Nov 30 20:17:02 UTC 2010


i'm building a listings site, where each post has two meta keys:

 - 'status' which can be a number of different values (e.g. active,
scheduled, awaiting payment, expired, error),
 - 'type' which can be a-premium, b-standard or c-normal.

on all multiple post pages (index, search, taxo, etc) i need to show only
those posts with a status of active, and they should be ordered by type (so
that premium listings appear before standard ones).

the first bit is easy enough, but i'm completely stuck on the second!

can anyone help with the SQL i need to achieve filtering on one meta value
while ordering on another?

i've pasted my current code at http://php.pastebin.com/Jg58KSz1 , this does
the filtering bit but not the ordering.

(ideally i would use custom post statuses for this, but this is not yet
fully developed enough in core to be usable.)

many thanks
simon


More information about the wp-hackers mailing list