[wp-hackers] WP_Query to sort by Custom Fields

Christopher Ross cross at thisismyurl.com
Mon May 16 13:15:04 UTC 2011

Is it possible to sort a WP_Query but custom field results (ideally multiple)?

I have a query that requires me to fetch a series of events, the site developer used a custom post type and inserted the day and month as custom fields, so now what I need to do is fetch the most recent 15 events. By default, it shows me the 15 that appeared in the database last but what I need is the month-day combo instead.

One way to do it obviously would be to fetch all events and then sort but there are thousands in the system. Even if I limited to just this month and last, there are still a lot. So, what's the best way to fetch and sort posts based on multiple custom fields?




Christopher Ross
Online Portfolio - http://christopherross.ca
Personal Blog - http://thisismyurl.com

Fredericton - 506.238.4661
San Diego   - 858.201.4912

More information about the wp-hackers mailing list