5

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?

4

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.

  • 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
  • 1
    it is "term_id" instead of "id". Possible values are 'term_id', 'name' and 'slug'. 'term_id' is default. – Shoaib Iqbal Sep 11 '15 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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