<p>The place to do that sort of thing is <a href="https://craftcms.com/classreference/services/StructuresService" rel="nofollow noreferrer">StructuresService</a>.</p>

<p>If we’re just talking about reordering a flat list of entries (no hierarchy), the only methods you need to worry about are <a href="https://craftcms.com/classreference/services/StructuresService#moveAfter-detail" rel="nofollow noreferrer">moveAfter()</a> (if an entry is being dragged after another one) and <a href="https://craftcms.com/classreference/services/StructuresService#prependToRoot-detail" rel="nofollow noreferrer">prependToRoot()</a> (if an entry is being dragged to the first position in the structure).</p>

<pre class="lang-php prettyprint-override"><code>$entry = craft()-&gt;entries-&gt;getEntryById(1);
$prevEntry = craft()-&gt;entries-&gt;getEntryById(2);
$structureId = $entry-&gt;getSection()-&gt;structureId;

craft()-&gt;structures-&gt;moveAfter($structureId, $entry, $prevEntry);
</code></pre>

CC BY-SA 3.0
2014-10-30T21:02:43.667Z
2017-10-26T09:27:51.087Z
2017-10-26T09:27:51.087Z
Brandon Kelly
<p>I've have a page that has a drag and drop ability to reorder a group of Structure entries (using jquery).</p>

<p>I see order inside EntryModel (<a href="https://craftcms.com/docs/templating/entrymodel" rel="nofollow noreferrer">https://craftcms.com/docs/templating/entrymodel</a>) but it looks like Structure positioning is handled outside the EntryModel.</p>

<p>Once dropped and and the entries are reordered it submits to an action inside a plugin. If I reorder two entries (or any number) how do I set the new structure order?</p>

<entries><structure>
How do I reorder Structure entries on the front-end?
# How do I reorder Structure entries on the front-end?

(Asked by: username_0 on 2014-10-29)

I've have a page that has a drag and drop ability to reorder a group of Structure entries (using jquery).

I see order inside EntryModel (<https://craftcms.com/docs/templating/entrymodel>) but it looks like Structure positioning is handled outside the EntryModel.

Once dropped and and the entries are reordered it submits to an action inside a plugin. If I reorder two entries (or any number) how do I set the new structure order?

**Tags:** entries, structure

---

## 1 answers

### Answer by username_1 on 2014-10-30. Score: 4 | Accepted answer

The place to do that sort of thing is StructuresService.
If we’re just talking about reordering a flat list of entries (no hierarchy), the only methods you need to worry about are moveAfter() (if an entry is being dragged after another one) and prependToRoot() (if an entry is being dragged to the first position in the structure).
$entry = craft()->entries->getEntryById(1);
$prevEntry = craft()->entries->getEntryById(2);
$structureId = $entry->getSection()->structureId;

craft()->structures->moveAfter($structureId, $entry, $prevEntry);


---

