diff --git a/src/Field/Gallery.php b/src/Field/Gallery.php index b1bb286..612f56b 100644 --- a/src/Field/Gallery.php +++ b/src/Field/Gallery.php @@ -30,7 +30,11 @@ public function process($field) { if ($ids = $this->fetchValue($field)) { $connection = $this->post->getConnectionName(); - $attachments = Post::on($connection)->whereIn('ID', $ids)->get(); + + $ids_ordered = implode(',', $ids); + + $attachments = Post::on($connection)->whereIn('ID', $ids) + ->orderByRaw("FIELD(ID, $ids_ordered)")->get(); $metaDataValues = $this->fetchMultipleMetadataValues($attachments); diff --git a/tests/ContentFieldsTest.php b/tests/ContentFieldsTest.php index 21995cb..c45ced5 100644 --- a/tests/ContentFieldsTest.php +++ b/tests/ContentFieldsTest.php @@ -97,8 +97,8 @@ public function testGalleryFieldValue() $this->assertTrue(strlen($image->url) > 0); } - // Testing the image in the 6th position - $image = $gallery->get()->get(6); + // Testing the image in the 0th position + $image = $gallery->get()->get(0); $this->assertEquals(1920, $image->width); $this->assertEquals(1080, $image->height); }