[Resolved] Issue with translating ACF repeater field
This thread is resolved. Here is a description of the problem and solution.
Problem: If you're experiencing issues with translating ACF repeater fields registered via PHP using the WPML editor, where the field doesn't translate correctly and only shows the number of rows instead of the array, this might be similar to your situation. Solution: We recommend trying the workaround mentioned in the WPML errata for issues related to the translation preference of PHP registered system fields. You can find more details and steps on how to apply this workaround at Advanced Custom Fields local fields translation preference issue for PHP registered system fields.
If this solution does not resolve your issue, or if it seems outdated or irrelevant to your specific case, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. Additionally, please feel free to open a new support ticket for further assistance at WPML support forum.
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
Background of the issue:
I am trying to translate ACF repeater fields registered via PHP using WPML. When translating posts using the WPML editor, the field doesn't translate correctly. Instead of showing the array, it only shows the number of rows. This issue is demonstrated in a post written in English (hidden link) and its translation (hidden link). However, when using the WordPress editor, the translation works as expected, as shown in these examples: English post (hidden link) and translated post (hidden link). The code used to register the field is in the 'Example field' plugin. You can download the plugin using the 'Download Plugins and Themes from Dashboard' plugin. Access to WP Admin is available with an account registered to wpml@wpml.org.
Symptoms:
When translating posts using WPML editor, the repeater field doesn't translate correctly and only shows the number of rows instead of the array.
Questions:
Why does the WPML editor not translate the ACF repeater field correctly?
How can I ensure the repeater field translates properly using WPML?
The repeater has wpml_cf_preferences set to 1 (copy). From what I can tell from your docs that's the correct setting for the repeater (https://wpml.org/tutorials/2022/06/how-to-translate-acf-repeater-fields/). The repeater only has one sub field which is a text field and that had the wpml_cf_preferences set to 2 (translate). Here is a gist of the whole plugin used for the example (hidden link).
Let me know if you require something else from me.
Hey Osama. I think you misunderstand the issue. The field in question is registered using code registration that both ACF and WPMl support. So there is no point for me to add a field on the sandbox site and create a group since the group is created via code. Or you can do that also since I provided a gist with the code. What I can do is install the plugin that creates the field. Does that work for you? Also how can I demonstrate the field result on the sandbox site? What I mean is my test site has a var_dump() function that shows the field value on the active theme. That's just the demonstration of what is the field value. How can I add that on the sandbox site?
Thanks for your reply. I uploaded the "Example field" plugin. After that, I used the following code to show the fields in the hidden link">single.php template.
// check if the repeater field has rows of data
if( have_rows('example_repeater') ):
// loop through the rows of data
while ( have_rows('example_repeater') ) : the_row();
// display a sub field value
the_sub_field('example_title');
endwhile;
else :
// no rows found
endif;
Please check this hidden link">post and try to replicate the issue there.
Hey Osama. Thank you for clearing this up and adding the code.
I've added the posts where you can see the issue. Here is the English post (hidden link) and here is the translation of that post (hidden link). As you can see on the English post the code you've added has data (hidden link) while the translation does't show anything (hidden link) but the values are present when I open the translation to edit it (hidden link).
What about the setting used in the code registration (hidden link). That is already set to be translatable so why isn't WPML picking up on that and also what about the meta key values in the admin? There are not visible in any other fields except now.
Hey Osama. It fixes the issue the problem is we can't switch to using the JSON. All of our fields are registered in code and to change them would be a massive cost on production. So from what I can see is this is a know bug. Do you know when will it be fixed?