Retrieve all posts within tag OR category?

I’ve created a simple loop. And I have the following array for the query:

$live_tags = array(
    'tag' => 'live',
    'showposts' => 5,
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'date',
    'order' => 'DESC'
    );

Where it says 'tag' => 'live', I need a logic that asks:

Read More
if ('tag' == 'live' || 'category' == 'candy')

But I am unsure how to do that within the WP_Query array.

Anyone know how to retrieve posts from either tag, or category?

Related posts

1 comment

  1. You need a tax_query.

    $live_tags = array(
      'posts_per_page' => 5, // showposts has been deprecated for a long time
      'post_type' => 'post',
      'post_status' => 'publish',
      'tax_query' => array(
        'relation' => 'OR',
        array(
          'taxonomy' => 'post_tag',
          'field' => 'slug',
          'terms' => 'live',
        ),
        array(
          'taxonomy' => 'category',
          'field' => 'slug',
          'terms' => 'candy',
        ),
      ),
      'orderby' => 'date',
      'order' => 'DESC'
    );
    $q = new WP_Query($live_tags);
    var_dump($q->request);
    

    Note that both the {tax} (string) and showposts arguments have been deprecated for quite some time. I would not recommend using them.

Comments are closed.