0

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?

Thanks!

2

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()) :
    $query->the_post();

    ...

endwhile;
// don't forget to reset/restore the query
wp_reset_postdata();
  • It ended up being tag and tag_not_in, but this put me in the right direction! Thanks! – Jacob Sep 23 '13 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 Sep 24 '13 at 7:18

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.