[wp-hackers] WP_Query to sort by Custom Fields

John Blackbourn johnbillion+wp at gmail.com
Mon May 16 13:17:45 UTC 2011


On 16 May 2011 14:15, Christopher Ross <cross at thisismyurl.com> wrote:
> 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?

Yep, see http://scribu.net/wordpress/advanced-metadata-queries.html


More information about the wp-hackers mailing list