Closed omzy closed 6 years ago
Just been looking in to this and I think the issue is on line 39 in Gallery.php
:
$attachments = Post::on($connection)->whereIn('ID', $ids)->get();
When you do a SQL IN query, it does not return the results in the order that you specify. This is default behaviour of SQL:
https://stackoverflow.com/questions/1631723/maintaining-order-in-mysql-in-query
I think we need to find a way to fix this because the JSON API returns the results in the correct order.
This works:
$ids_ordered = implode(',', $ids);
$attachments = Post::on($connection)->whereIn('ID', $ids)
->orderByRaw("FIELD(ID, $ids_ordered)")->get();
Reference: https://stackoverflow.com/questions/26704575/laravel-order-by-where-in
What do you think @jgrossi?
@omzy83 go ahead and send a PR ;-) thanks
@jgrossi PR is here: https://github.com/corcel/acf/pull/56
I have added some images with the gallery field. I then re-ordered the images in the admin, however on the front end it is still showing the images in the previous order. In the admin I can see the images are in the new order after refreshing the page.
Is this an issue with corcel or with acf?
I output the images as follows: