diff --git a/src/Twig/FieldExtension.php b/src/Twig/FieldExtension.php index 5c669f389..f8ae29a84 100644 --- a/src/Twig/FieldExtension.php +++ b/src/Twig/FieldExtension.php @@ -105,7 +105,13 @@ public function getSelected(Field\SelectField $field, $returnsingle = false, $re $ids = $field->getValue(); // Find records by their respective ids - $records = $this->contentRepository->findBy(['id' => $ids]); + $records = collect($this->contentRepository->findBy(['id' => $ids])); + + // Sort the results in the order of the $ids. + $order = array_flip($ids); + $records = $records->sortBy(function (Content $record) use ($order) { + return $order[$record->getId()]; + })->toArray(); if ($returnsingle || (! $returnarray && $definition->get('multiple') === false)) { return current($records);