<p>This question is old, but the solution is: </p>

<pre><code>// look up parent with a ElementCriteriaModel

$parentCriteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);

$parentCriteria-&gt;search  = 'slug:'.$parentSlug; // whatever you have

$parent = $parentCriteria-&gt;find()[0];

$entry = new EntryModel();
$entry-&gt;sectionId = $section;

$entry-&gt;parentId = $parent-&gt;id; 

...
</code></pre>

CC BY-SA 3.0
2015-11-23T20:33:18.460Z
2015-11-23T20:33:18.460Z
gromgull
<p>I have Structure-type Section for entries and want to pragmatically populate a large list of multi-tiered entries.</p>

<p>I see you can create an entry like:</p>

<pre><code>$entry = new EntryModel();
$entry-&gt;getContent()-&gt;title = 'New Page';
$entry-&gt;getContent()-&gt;body = null;

craft()-&gt;entries-&gt;saveEntry($entry);
</code></pre>

<p>What I want to do is add the parent(s) of the entry, something like:</p>

<pre><code>$entry = new EntryModel();
$entry-&gt;getContent()-&gt;title = 'New Page';
$entry-&gt;getContent()-&gt;body = null;

// this entry would be a child in order of Sports -&gt; Tennis -&gt; This Entry
$entry-&gt;getContent()-&gt;parent = sports-&gt;tennis;

craft()-&gt;entries-&gt;saveEntry($entry);
</code></pre>

<p>Is there a way to do something like that?</p>

CC BY-SA 3.0
2015-06-26T03:17:18.050Z
Anyone have any ideas??
user2056505
<plugin-development><entry><entry-type><php>
Set Structure Parent when creating Entry in Plugin
# Set Structure Parent when creating Entry in Plugin

(Asked by: username_0 on 2015-06-03)

I have Structure-type Section for entries and want to pragmatically populate a large list of multi-tiered entries.
I see you can create an entry like:
$entry = new EntryModel();
$entry->getContent()->title = 'New Page';
$entry->getContent()->body = null;

craft()->entries->saveEntry($entry);

What I want to do is add the parent(s) of the entry, something like:
$entry = new EntryModel();
$entry->getContent()->title = 'New Page';
$entry->getContent()->body = null;

// this entry would be a child in order of Sports -> Tennis -> This Entry
$entry->getContent()->parent = sports->tennis;

craft()->entries->saveEntry($entry);

Is there a way to do something like that?

**Tags:** plugin-development, entry, entry-type, php

> **Comments:**
> **username_0**: Anyone have any ideas??  

---

## 1 answers

### Answer by username_1 on 2015-11-23. Score: 4

This question is old, but the solution is: 
// look up parent with a ElementCriteriaModel

$parentCriteria = craft()->elements->getCriteria(ElementType::Entry);

$parentCriteria->search  = 'slug:'.$parentSlug; // whatever you have

$parent = $parentCriteria->find()[0];

$entry = new EntryModel();
$entry->sectionId = $section;

$entry->parentId = $parent->id; 

...


---

