Is it possible to only include posts with a specific tag in this query?

<?php $query = new WP_Query
            (array('showposts' => 5, 'orderby' => 'date', 'order' => 'DESC'));
            while ($query->have_posts()) : $query->the_post();?>

Also is there also a way to exclude posts with a certain tag as well?


1 Answer 1


It seems you're looking for the tag parameters:

$args = array(
    'posts_per_page' => 5,
    'tag' => 'YOUR-TAG-SLUG',
    'orderby' => 'date',
    'order' => 'DESC',
$query = new WP_Query($args);
while ($query->have_posts()) :


// don't forget to reset/restore the query
  • It ended up being tag and tag_not_in, but this put me in the right direction! Thanks!
    – Jacob
    Commented Sep 23, 2013 at 22:43
  • 1
    Sorry, my bad. I absolutely misinterpreted your question and thought you meant parameter/argument when saying tag - and not an actual post tag. I'll update my answer. Glad it pointed you in the right direction anyway.
    – tfrommen
    Commented Sep 24, 2013 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.