WordPress – Query posts that do NOT have certain tag

How can I specify in my posts query that I only want to have posts without any tags at all? Pretty simple question, don’t think I need to elaborate much more than this.

So to get posts WITH a tag I would do query_posts('tag=this').

Related posts

Leave a Reply

1 comment

  1. Use tag__not_in(/* array of tag id values */).

    If you wanted to exclude all tags, you would need to build up an array using the full list of tags retrieved using get_tags(). That method will return an array of tag objects, where the term_id property is the id for that tag. Example:

    $tags = get_tags();
    for ($i=0;  $i < count($tags); $i++)
    {
        $tag_id_array[$i] = $tags[$i]->term_id;
    }
    

    For more info on query parameters, see here.