Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a wp_query that works great but I can't have both a meta query and a tax_query in it.

<?php 
    $event_query = new WP_Query(
        array( 
          'post_type'  => 'event',        // only query events
          'meta_key'    => 'event-date',  // load up the event_date meta
          'orderby'     => 'meta_value',
          'order'       => 'asc',         // ascending, so earlier events first
          'posts_per_page' => '-1',
          'meta_query'  => array(
             array(         // restrict posts based on meta values
              'key'     => 'event-date',  // which meta to query
              'value'   => date("Y/m/d"),  // value for comparison
              'compare' => '>',          // method of comparison
              'type'    => 'DATE'  )
             ),
          'tax_query' => array(
            array(
                'taxonomy'  => 'event_category',
                'field'     => 'slug',
                'terms'     => $term_id,
                'operator'  => 'IN')

                ),

           ) // end array
        ); // close WP_Query constructor call

?>

I am trying to find all the events in taxonomy $term_id and then make sure they are all in the future and order by ASC

Any ideas?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The query looks about right and I know that meta_query and tax_query work together just fine. the only thing i can think of is that you are query taxonomy by slug and passing the term id which are two different things, change:

'field'     => 'slug',

with

'field'     => 'id',

in your tax_query.

share|improve this answer
    
I tried that with no change. I think the issue is how I am deriving id. I don't think its coming up with the right id –  TJ Sherrill Jun 14 '11 at 16:26
    
You were right, I left the Field as Slug and then setup a variable with the slug in it and used that. Thanks –  TJ Sherrill Jun 14 '11 at 16:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.