AdvancedCustomFields / AdvancedCustomFields/acf
ACF Pro: Gallery Field incompatible sort with WPML
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
Hello Guys,
I have a big problem with the gallery field when I using WPML, too.
On translated pages the Order of the Images is lost and it order instead from lowest to highest Post-ID.
I debug it down and that my Report (with example IDs).
- Call Gallery Field:
$images = get_field('gallery_field'. $post_id);
Expected Behavior of the Array Post-Ids: 5, 4, 6, 9.
The resulted Array: 4, 5, 6, 9.
get_fieldusesacf_get_postswithpost__in
The Method get_attachments uses following code:
// get posts
$posts = acf_get_posts(array(
'post_type' => 'attachment',
'post__in' => $post__in
));
acf_get_postscallget_posts, which is modified by WPML
See: https://github.com/AdvancedCustomFields/acf/blob/master/includes/api/api-helpers.php#L1596
acf_get_postsTry to validate the Order
See: https://github.com/AdvancedCustomFields/acf/blob/master/includes/api/api-helpers.php#L1604
The $order Array Contains now only falses and with array_multisort the "right" order will be resetted to "from lowest to highest".
I hope you can find a fix for this :)
Best Regards
Sysix
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in includes/api/api-helpers.php at the get_attachments and acf_get_posts paths referenced in the report, then reproduce the gallery lookup on a translated page with WPML. Compare the requested post IDs with the returned array and verify that the expected image order is preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend, internationalization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100