tax_query: What to pass when I want to have all terms?

…

$args = array(
    'post_type' => 'wr_event',
    'posts_per_page' => -1,
    'meta_key' => 'event_date',
    'orderby' => 'meta_value_num',
    'order' => $order,
    'meta_value' => $yesterday,
    'meta_compare' => $compare,
    if ( is_null($cat) )
        'tax_query' => array(
            array(
                'taxonomy'  => 'event_type',
                'field'     => 'slug',
                'terms'     => $cat,
                'operator'  => 'IN'
                ),
           )
);

I’m confused, what do I pass in order to get all posts from all terms?
Right now I can for instance pass sports in order to get all sports-events, but how do I get all events? I know I could just get rid of the tax_query() however I’m using this as a param, where I can pass along a certain tax or if not, i want all posts.

Related posts

1 comment

  1. Simply omit (or not add) tax_query part of arguments.

    $args = array(
        'post_type' => 'wr_event',
        'posts_per_page' => -1,
        'meta_key' => 'event_date',
        'orderby' => 'meta_value_num',
        'order' => $order,
        'meta_value' => $yesterday,
        'meta_compare' => $compare,
    );
    
    if ( ! is_null($cat) )
      $args['tax_query'] =array(
                array(
                    'taxonomy'  => 'event_type',
                    'field'     => 'slug',
                    'terms'     => $cat,
                    'operator'  => 'IN'
                    ),
               );
    

Comments are closed.