# Etiquetado masivo de temas basado en palabras clave

**URL:** https://meta.discourse.org/t/bulk-tagging-topics-based-on-keywords/120526
**Category:** Support
**Created:** [16 Junio, 2019 16:20 UTC](https://meta.discourse.org/t/bulk-tagging-topics-based-on-keywords/120526 "2019-06-16T16:20:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [16 Junio, 2019 16:20 UTC](https://meta.discourse.org/t/bulk-tagging-topics-based-on-keywords/120526/1 "2019-06-16T16:20:48Z")

</div>

Hi,

In order to use the new ‘[no ads for tags](https://meta.discourse.org/t/exclude-topic-from-adsense/95281/17)’ support in the ad plugin, we need to mass-tag any ‘nswf’ topics on our forum based on specific keywords. For example, any topic that contains the word ‘nude’ in the title or any post in the topic needs to be tagged nsfw.

We have a list of such keywords, so the logic that I’m looking for is:

```plaintext
IF the topic title OR any post in this topic
CONTAINS word-1 or word-2 ..
THEN apply a tag to the topic

```

I found [this topic](https://meta.discourse.org/t/batch-tagging-through-console/47602/2), but my case seems a little more complex. Can someone help me out with a query to achieve this?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [16 Junio, 2019 21:40 UTC](https://meta.discourse.org/t/bulk-tagging-topics-based-on-keywords/120526/2 "2019-06-16T21:40:54Z")

</div>

I’m on my phone. Here are some parts

```
   posts = Post.where("raw like '%badword%')
 posts.each do |post|
 Tag.create(some stuff here) # this won't work
 end

```

If there are lots of words, you’d stick them in an arrays and loop through them. You’ll need to find an example of what fields are required to create a tag. Probably topic\_id and name.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [24 Noviembre, 2022 19:31 UTC](https://meta.discourse.org/t/bulk-tagging-topics-based-on-keywords/120526/3 "2022-11-24T19:31:48Z")

</div>



---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [27 Noviembre, 2022 12:20 UTC](https://meta.discourse.org/t/bulk-tagging-topics-based-on-keywords/120526/4 "2022-11-27T12:20:46Z")

</div>


