I'd like to attach children to a specific Structure entry in a specific order...
- Entry A
- Entry B
- Imported Entry 2
- Imported Entry 1
- Imported Entry 3
- Entry C
I've got a $records
array to turn into imported entries:
array(
'name' => 'Whatever',
'updated_at' => '2014-02-27T04:14:29Z',
'position' => 1, // int representing the sort order
[...]
)
As I'm looping through my array to create new Craft Structure Entries, I need to be able to define the parent (Entry B), I'm just not sure how. I've figured out how to attach new children to Entry B, I just don't know how to programmatically set their order. My imagination writes code that looks like this:
$parentCriteria = craft()->elements->getCriteria(ElementType::Entry);
$parentCriteria->search = 'slug:entry-b';
$parentCriteria->section = 'sectionName';
$parentCriteria->type = 'sectionType';
$entries = $parentCriteria->find();
$parent = $entries[0];
foreach ($records as $row)
{
$entry = new EntryModel();
$entry->sectionId = 4;
$entry->typeId = 4;
$entry->parentId = $parent->id;
$entry->authorId = 1;
$entry->postDate = $row->updated_at;
$entry->title = $row->name;
$entry->sortOrder = $row->position; // ← quite impossible!
$success = craft()->entries->saveEntry($entry);
}
It's $entry->sortOrder
that's completely made up—how do you attach an entry to a specific parent in a specific order?