what is query tag?

Perform alterations to a structured query for a given tag.

   Any dynamic Select query may be "tagged" with one or more strings. These tags serve to identify the type of query it is, which in turn allows alter hooks to determine if they need to take action.

   To add a tag to a query, use the addTag() method:
   $query->addTag('node_access');

   Register the tag to alter the query instance using hook_query_TAG_alter

   there are three methods available:

    // TRUE if this query object has this tag.
    $query->hasTag('example');

    // TRUE if this query object has every single one of the specified tags.
    $query->hasAllTags('example1', 'example2');

    // TRUE if this query object has at least one of the specified tags.
    $query->hasAnyTag('example1', 'example2');
    Both hasAllTags() and hasAnyTag() take an arbitrary number of parameters with each tag as its own parameter

   
   <?php
    /**
     * Implements hook_query_TAG_alter()
     */
    function hook_query_node_is_not_tagged_alter(QueryAlterableInterface $query) {
      $query->leftJoin('field_data_field_tags', 'o', 'node.nid = o.entity_id AND o.entity_type = :entity_type');
      $query->isNull('o.field_tags_tid');
    }
    //This query tag alter only works for the "node" entity type. 

    //Get all the nodes from that doesn't been tagged yet using EntityFieldQuery, look at the addTag() method:
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node')
      ->entityCondition('bundle', 'news')
      ->addTag('node_is_not_tagged')
      ->propertyCondition('status', 1);
    $result = $query->execute();

    ?>

Tags