# Batch tagging through console

**URL:** https://meta.discourse.org/t/batch-tagging-through-console/47602
**Category:** 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:** 5

<div class="post-metadata">

### Author: ![chrisc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrisc/32/119982_2.png) [@chrisc](https://meta.discourse.org/u/chrisc)
#### Post date: [October 26, 2017, 10:22am UTC](https://meta.discourse.org/t/batch-tagging-through-console/47602/5 "2017-10-26T10:22:39Z")

</div>

Sorry I should have played with this more before asking for help, the following appears to work if you create the tag on a post first:

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

Topic.where(category: category).each do |topic|
  if topic.tags.exclude?(tag)
    topic.tags << tag
  end
end

```

---

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