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?

1 Answer 1


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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.