Skip to content

Commit 981069b

Browse files
authored
Merge pull request #56 from omzy83/ACF-50
maintain image order
2 parents 32ecfc9 + 94d9d88 commit 981069b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Field/Gallery.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public function process($field)
3030
{
3131
if ($ids = $this->fetchValue($field)) {
3232
$connection = $this->post->getConnectionName();
33-
$attachments = Post::on($connection)->whereIn('ID', $ids)->get();
33+
34+
$ids_ordered = implode(',', $ids);
35+
36+
$attachments = Post::on($connection)->whereIn('ID', $ids)
37+
->orderByRaw("FIELD(ID, $ids_ordered)")->get();
3438

3539
$metaDataValues = $this->fetchMultipleMetadataValues($attachments);
3640

tests/ContentFieldsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ public function testGalleryFieldValue()
9797
$this->assertTrue(strlen($image->url) > 0);
9898
}
9999

100-
// Testing the image in the 6th position
101-
$image = $gallery->get()->get(6);
100+
// Testing the image in the 0th position
101+
$image = $gallery->get()->get(0);
102102
$this->assertEquals(1920, $image->width);
103103
$this->assertEquals(1080, $image->height);
104104
}

0 commit comments

Comments
 (0)