Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to query posts which do not have tags assigned to them?

query_posts('tag='tag_exmaple'&posts_per_page=-1');      

Ty very much!

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Either use the tag_not_in parameter if you have the tag id and if not then you can use tax_query parameter like so:

$tag_to_exclude = 'example_tag';
$args = array(
'posts_per_page' => -1,
'tax_query' => array(
        array(
            'taxonomy' => 'post_tag',
            'field' => 'slug',
            'terms' => array($tag_to_exclude),
            'operator' => 'NOT IN',
        )
);
query_posts($args);
share|improve this answer

You could get an array of all of the tag ids and send it to the "tag__not_in" parameter. Not the most elegant solution, but I'm not sure how else it would be accomplished.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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