[wp-hackers] advice on custom field post-query

Austin Matzko if.website at gmail.com
Mon Oct 12 18:46:13 UTC 2009


On Mon, Oct 12, 2009 at 1:40 PM, Sharon Chambers <sharon at brewerradio.com> wrote:
> I was hoping to find some advice on how best to achieve what I’m trying to do…
>
> I’ve got two custom fields:  _bec_beginning, _bec_expiration
> I’m trying now to structure a query that will give me all posts for a date that is within the range of _bec_beginning to _bec_expiration.  What I’m trying is not working:
>
> “showposts=$limit&post_type=post&meta_key=_bec_expiration&meta_compare=>=&meta_value=$date&meta_key=_bec_beginning&meta_compare=<=&meta_value=$date”
> Where $date is, of course the date in question.
> I’m not entirely sure it’s possible to query_posts in this fashion, using two custom fields, and I’m not confident that the meta_compare works quite right either.

It's not possible currently to query for more than one meta_key/_value
pair using the WP query API alone.

I've done almost the exact same thing you're trying to accomplish by
using the posts_join and posts_where filters to supplement the query
with the extra joins on the postmeta table.


More information about the wp-hackers mailing list