# Batch tagging through console

**URL:** <https://meta.discourse.org/t/batch-tagging-through-console/47602>\
**Category:** Product Support\
**Created:** [July 21, 2016, 2:22pm UTC](https://meta.discourse.org/t/batch-tagging-through-console/47602 "2016-07-21T14:22:52Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)\
**Post date:** [December 13, 2017, 9:05pm UTC](https://meta.discourse.org/t/batch-tagging-through-console/47602/7 "2017-12-13T21:05:12Z")

</div>

To append a tag to every topic on a forum, first ensure the tag is used on at least one topic. Then run the following (replacing `testing` with the name of the tag)

```plaintext
tag = Tag.find_by(name: 'testing')

Topic.where(archetype: 'regular').find_each do |topic|
 if topic.tags.exclude?(tag)
   topic.tags << tag
 end
end

```

To append a tag to every topic on the forum _that does not have any tags already_, first ensure the tag is used on at least one topic. Then run the following (replacing `testing` with the name of the tag)

```plaintext
tag = Tag.find_by(name: 'testing')

Topic.where(archetype: 'regular').find_each do |topic|
  if topic.tags.count == 0
    topic.tags << tag
  end
end

```

---

_[View the full topic](https://meta.discourse.org/t/batch-tagging-through-console/47602)._
