<p>The <a href="https://craftcms.com/docs/templating/entrymodel" rel="nofollow noreferrer">EntryModel</a> you have has a <a href="https://craftcms.com/docs/templating/entrymodel#sectionId" rel="nofollow noreferrer">sectionId</a> property you can set.  i.e.</p>

<pre><code> $entry = new EntryModel();
 $entry-&gt;sectionId = 1;
 $saveIt = craft()-&gt;entries-&gt;saveEntry($entry);
</code></pre>

<p>Note that there are other properties you'll need to set for it to pass validation.  So, if <code>$saveIt</code> is false after calling <code>saveEntry($entry)</code>, then call <code>$entry-&gt;getErrors()</code> to get an array of validation errors to fix.</p>

CC BY-SA 3.0
2018-01-26T16:38:43.640Z
Thanks Brad. I was confused how to refer to the section by name, which obviously is not possible.
Dan Zuzevich
CC BY-SA 3.0
2018-01-26T21:09:59.187Z
@DanielZuzevich for future reference if it's really necessary for whatever reason to set something by handle (not name, the name is not unique) instead of the ID you could do `$entry->sectionId = craft()->sections->getSectionByHandle('handle')->id`
Robin Schambach
CC BY-SA 3.0
2018-01-25T21:50:07.793Z
2018-01-26T20:48:07.507Z
2018-01-26T20:48:07.507Z
Brad Bell
<p>Let's say I created a section called, "Answers". In a custom plugin, I want to create an entry that should show up under the "Answers" tab in the CP entries page.</p>

<pre><code>  $entry = new EntryModel();
  // How do I say, save this entry into the "Answers" channel?
  $saveIt = craft()-&gt;entries-&gt;saveEntry($entry);
</code></pre>

<p><a href="https://i.sstatic.net/Urlio.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Urlio.png" alt="enter image description here"></a></p>

<p>I have literally been reading Craft docs for the past hour, and have gotten nowhere.</p>

<plugin-development><entries>
Creating a new entry in a specific section
# Creating a new entry in a specific section

(Asked by: username_0 on 2018-01-25)

Let's say I created a section called, "Answers". In a custom plugin, I want to create an entry that should show up under the "Answers" tab in the CP entries page.
  $entry = new EntryModel();
  // How do I say, save this entry into the "Answers" channel?
  $saveIt = craft()->entries->saveEntry($entry);


I have literally been reading Craft docs for the past hour, and have gotten nowhere.

**Tags:** plugin-development, entries

---

## 1 answers

### Answer by username_1 on 2018-01-25. Score: 3 | Accepted answer

The EntryModel you have has a sectionId property you can set.  i.e.
 $entry = new EntryModel();
 $entry->sectionId = 1;
 $saveIt = craft()->entries->saveEntry($entry);

Note that there are other properties you'll need to set for it to pass validation.  So, if $saveIt is false after calling saveEntry($entry), then call $entry->getErrors() to get an array of validation errors to fix.

> **Comments:**
> **username_0**: Thanks Brad. I was confused how to refer to the section by name, which obviously is not possible.  
> **username_2**: @DanielZuzevich for future reference if it's really necessary for whatever reason to set something by handle (not name, the name is not unique) instead of the ID you could do `$entry->sectionId = craft()->sections->getSectionByHandle('handle')->id`  

---

