tax_query in WP_Query problem

Thanks to Rarst for pointing me in the right direction. After a bit of playing around the following query is now producing the effect I’m after:

$query_args = array(
    'numberposts' => $limit,
    'order' => 'DESC',
    'orderby' => 'post_date',
    'post_type' => 'match',
);

$query_args['meta_query'] = array(
    'key' => 'played',
    'value' => true,
);

if ( isset( $comp ) )
    $query_args['tax_query'][] = array(
        'taxonomy' => 'comp',
        'terms' => $comp,
        'field' => 'term_id',
    );

if ( isset( $season ) )
    $query_args['tax_query'][] = array(
        'taxonomy' => 'season',
        'terms' => $season,
        'field' => 'term_id',
    );

if ( isset( $team ) )
    $query_args['tax_query'][] = array(
        'taxonomy' => 'team',
        'terms' => $team,
        'field' => 'term_id',
    );

if ( $venue > 0  )
    $query_args['tax_query'][] = array(
        'taxonomy' => 'venue',
        'terms' => $venue,
        'field' => 'term_id',
    );

Leave a Comment