Skip to content

Commit

Permalink
Merge pull request #56 from omzy83/ACF-50
Browse files Browse the repository at this point in the history
maintain image order
  • Loading branch information
jgrossi authored Feb 9, 2018
2 parents 32ecfc9 + 94d9d88 commit 981069b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Field/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/ContentFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 981069b

Please sign in to comment.