humanmade / humanmade/network-media-library
Images in ACF repeaters returns the same image (last one) for any repeating element
- Dominant language
- PHP
- Stars
- 296
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
If you create an ACF repeater containing an image it will correctly return the structure of the sub fields, but the value for image is all the same for each repeater row. And it is the value of the last image in the repeater set.
The fix is fairly easy, but I cannot provide a real PR right now. Instead I can document the required change here.
The reason is that the two hooks in place here
```
add_filter( "acf/load_value/type={$type}", [ $this, 'filter_acf_attachment_load_value' ], 0, 3 );
add_filter( "acf/format_value/type={$type}", [ $this, 'filter_acf_attachment_format_value' ], 9999, 3 );
```
are not called for each repeating row alternately, but it will call n times load_value and n times format_value. To solve this I simply pushed the values an an array and grab them later from that array.
so I declared:
`protected $values = []; // null;
`
and then assigned this way
`$this->values[] = $image; // $this->value = $image;
`
and finally pulled the value here
`return array_shift( $this->values ); // return $this->value;
`
i hope this is easy enough to understand to put this back into the main code repo,
Best
-Elmar
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the acf/load_value/type and acf/format_value/type hooks and their filter_acf_attachment_load_value and filter_acf_attachment_format_value callbacks. Verify how repeater rows are processed, then confirm that each row returns its own image rather than the final image in the repeater.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100