Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-26T16:38:43.640Z
Answers.Text: Thanks Brad. I was confused how to refer to the section by name, which obviously is not possible.
Answers.UserDisplayName: Dan Zuzevich
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-26T21:09:59.187Z
Answers.Text: @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`
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-25T21:50:07.793Z
Answers.LastActivityDate: 2018-01-26T20:48:07.507Z
Answers.LastEditDate: 2018-01-26T20:48:07.507Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Tags: <plugin-development><entries>
Title: Creating a new entry in a specific section
ThreadText: # 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);
  
  ```
  
  [![enter image description here](https://i.sstatic.net/Urlio.png)](https://i.sstatic.net/Urlio.png)
  
  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](https://craftcms.com/docs/templating/entrymodel) you have has a [sectionId](https://craftcms.com/docs/templating/entrymodel#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 username_1. 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`  
  
  ---
  
  