Support » Fixing WordPress » Looking for WP_Query help

  • I’m trying to add a condition to a query string and am striking out. I’ve read through the support docs several times and am either just missing the answer or am too inexperienced to see it.

    This is my current string:

    <?php $recent = new WP_Query( 'cat=7,316&posts_per_page=10' ); ?>

    And what I want to do is also include posts from a certain tag, so I tried adding


    But I realize this is probably saying “give me all posts with a cat id of 7 AND a tag id of 7, and what I want is cat 7 OR tag 7.

    I think one easy answer here is to just use create and include a third category, but I am trying to include these post headlines in a specific spot on the homepage without them showing up on a separate category archive page.

Viewing 1 replies (of 1 total)
  • You need to use a ‘tax_query’ as described here:

    Your code would look something like this:

    $args = array(
       'post_type' => 'post',
       'posts_per_page' => 10,
       'tax_query' => array(
          'relation' => 'OR',
             'taxonomy' => 'category',
             'field' => 'id',
             'terms' => array( 7, 316 )
             'taxonomy' => 'post_tag',
             'field' => 'id',
             'terms' => 7
    $recent = new WP_Query($args);
Viewing 1 replies (of 1 total)
  • The topic ‘Looking for WP_Query help’ is closed to new replies.