[wp-hackers] WP_Query to sort by Custom Fields
Gavin Pearce
Gavin.Pearce at 3seven9.com
Tue May 17 12:59:45 UTC 2011
+1 ... update the post type to make use of UNIX timestamps (then apply
it retrospectively).
You can then just select any events "<" than the current timestamp, and
LIMIT to 15 etc ...
For queries where you need a particular month, you select any items
between the timestamps for month start and end. Sorry if teaching to
suck eggs!
Gavin
-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Daniel
Bachhuber
Sent: 16 May 2011 14:27
To: wp-hackers at lists.automattic.com
Subject: Re: [wp-hackers] WP_Query to sort by Custom Fields
A better solution to your problem would be to store the event day and
month together as a UNIX timestamp. It's a simpler query and will be
more flexible in the long run.
On May 16, 2011, at 9:17 AM, John Blackbourn <johnbillion+wp at gmail.com>
wrote:
> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list