1

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:

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?

4

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.

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.