# Auto Tagging feature plugin

**URL:** https://meta.discourse.org/t/auto-tagging-feature-plugin/168321
**Category:** Development
**Created:** [October 26, 2020, 8:19pm UTC](https://meta.discourse.org/t/auto-tagging-feature-plugin/168321 "2020-10-26T20:19:06Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![feabila](https://avatars.discourse-cdn.com/v4/letter/f/e9bcb4/32.png) [@feabila](https://meta.discourse.org/u/feabila)
#### Post date: [October 26, 2020, 8:19pm UTC](https://meta.discourse.org/t/auto-tagging-feature-plugin/168321/1 "2020-10-26T20:19:06Z")

</div>

Hi everyone! I’m creating a system which tags are created automatically, so every person could create tags!

About this matter:

- Tags are create in form of topic creation
- If there isn’t a tag in which the person mentioned, it will ignore by default in post

My goal was to create a way of auto tagging, so if #test1 doesn’t exist, create it automatically and refresh cooked of post to update the link to tags and so on.

So, i was trying some ways to perform this demand, so i would like to show you and ask if there is a better way to achieve my goal.

```
after_initialize do
   DiscourseEvent.on(:post_created) do |post, _, user|
      # Passing from category tags (#test:item1)
      tags= post.raw.split(' ').select{|t| t =~ /#/ && !t.include?(':')}
      tags.each do |t|
        tName= t.gsub('#', '')
        Tag.create_or_find_by(name: tName);
      end

      postAnalyzer= PostAnalyzer.new(post.raw, post.topic_id)
      cookedRaw= postAnalyzer.cook(post.raw)

      post.cooked= cookedRaw
      post.save

      post.publish_change_to_clients!(:revised, reload_topic: true)
   end
end

```

Appreciate your help!
