[wp-hackers] Sorting Meta Fields

Dave Hendler sollaires at gmail.com
Thu Dec 15 16:49:26 GMT 2005

Hey all,

I'm new to Wordpress hacking, but I thought this might be a useful
patch.  I wanted to be able to sort posts by meta fields so I hacked
some preliminary support into WP_Query->get_posts().  Basically, if
the orderby parameter sent to query_posts() is not in the allowed
array (author,date,category,title), I perform an additional join to
the postmeta table and mess about a little bit to get things working. 
If the meta data is not a string value, the ordercast variable is used
to specify how to treat that field (i.e. signed, unsigned, decimal,etc
- it currently maps directly to the MySQL cast types).  I'm currently
using it experimentally to have a category of reviews with a numeric
score attached to posts.  My thought is that by supporting it deeper
within wp, it will be easier to hook this kind of extension into
paging and other deeper functionality.  I've seen a couple of
discussion threads on the public site asking for this kind of feature,
so I'd thought I'd throw it to you guys to figure out where to go from

Is this something I should submit to SVN?  How should I go about this?

- dave

dave hendler

More information about the wp-hackers mailing list