<p>You were on the right track. To save things in Craft, you need to use the according service. In your case you need the tags service:</p>
<pre class="lang-php prettyprint-override"><code>$tagGroup = new TagGroup();
$tagGroup-&gt;name = 'GroupName';
$tagGroup-&gt;handle = 'GroupHandle';
$isTagGroupSaved = Craft::$app-&gt;getTags()-&gt;saveTagGroup($tagGroup);

if(!$isTagGroupSaved) {
    // Inspect validation errors if saving the tag group failed
    var_dump($tagGroup-&gt;getErrors());
}
</code></pre>

CC BY-SA 4.0
2021-03-09T11:28:13.090Z
Thanks! This fixed the problem :D
randomGuy
CC BY-SA 4.0
2021-03-08T15:42:52.243Z
2021-03-08T15:42:52.243Z
nstCactus
<p>I'm new to the Craft CMS framework and have a question about tags. How can I create a new tag group?</p>
<p>You can create a tag list by hand via the admin panel &gt; settings &gt; Tag Groups &gt; New Tag Group.
This is a way I can't use for plug-in development. So far as I know, I have to use the following code:</p>
<pre><code>    $tagGroup = new TagGroup();
    $tagGroup-&gt;name = 'GroupName';
    $tagGroup-&gt;handle = 'GroupHandle';
</code></pre>

<plugin-development><craft3>
How to create a new Tag group and save it?
# How to create a new Tag group and save it?

(Asked by: username_0 on 2021-03-08)

I'm new to the Craft CMS framework and have a question about tags. How can I create a new tag group?
You can create a tag list by hand via the admin panel > settings > Tag Groups > New Tag Group.
This is a way I can't use for plug-in development. So far as I know, I have to use the following code:
    $tagGroup = new TagGroup();
    $tagGroup->name = 'GroupName';
    $tagGroup->handle = 'GroupHandle';

**Tags:** plugin-development, craft3

---

## 1 answers

### Answer by username_1 on 2021-03-08. Score: 1 | Accepted answer

You were on the right track. To save things in Craft, you need to use the according service. In your case you need the tags service:
$tagGroup = new TagGroup();
$tagGroup->name = 'GroupName';
$tagGroup->handle = 'GroupHandle';
$isTagGroupSaved = Craft::$app->getTags()->saveTagGroup($tagGroup);

if(!$isTagGroupSaved) {
    // Inspect validation errors if saving the tag group failed
    var_dump($tagGroup->getErrors());
}

> **Comments:**
> **username_0**: Thanks! This fixed the problem :D  

---

