AdvancedCustomFields / AdvancedCustomFields/acf

ACF Pro: Gallery Field incompatible sort with WPML

Open
#101 3 comments 0 reactions 0 assignees View on GitHub

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).

  1. 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.

  1. get_field uses acf_get_posts with post__in

The Method get_attachments uses following code:

	// get posts
	$posts = acf_get_posts(array(
		'post_type'	=> 'attachment',
		'post__in'	=> $post__in
	));
  1. acf_get_posts call get_posts, which is modified by WPML

See: https://github.com/AdvancedCustomFields/acf/blob/master/includes/api/api-helpers.php#L1596

  1. acf_get_posts Try 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.