Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is using the

acfml_should_translate_acf_entity

hook to control the translation of ACF fields based on their keys. Despite the function returning false for fields with keys including '_level', these fields still appear in the WPML translation editor.
Solution:
1. We recommended verifying the translation settings directly in the PHP code for ACF fields and adjusting them as necessary. Documentation on setting translation preferences for ACF fields created using PHP can be found here: Setting the translation preferences for ACF fields created using PHP code.
2. For fields like links within repeaters, where only the label should be translatable, it's a known issue. A workaround is suggested while a fix is planned for ACFML 2.2.0. More details can be found in this forum post: Translating ACF link field in Advanced Translation Editor.

If this solution does not resolve your issue or seems outdated, please check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. If the problem persists, we highly recommend opening a new support ticket 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.

This topic contains 5 replies, has 0 voices.

Last updated by Dražen 2 months, 3 weeks ago.

Assisted by: Dražen.

Author Posts
March 10, 2025 at 3:44 pm #16797419

michelleM-18

Background of the issue:
I am trying to use the 'acfml_should_translate_acf_entity' hook for Advanced Custom Fields Multi Language. This code correctly returns true or false on fields that include the key _level. However, the field isn't removed from the WPML translation editor.

add_filter('acfml_should_translate_acf_entity', function ($shouldTranslate, $acfField, $postId) {
$excludedPatterns = [
'/_level/',
'/_Level/'
];

if (!empty($acfField['key'])) {
foreach ($excludedPatterns as $pattern) {
if (preg_match($pattern, $acfField['key'])) {
return false;
}
}
}

return $shouldTranslate;
}, 10, 3);

The response from this function: - These are the correct responses - the _level returning false should not appear in the WPML Translation editor at hidden link.

126:string '_field_cont-contheading_title' (length=29)
147:boolean true
126:string '_field_cont-contheading_title_level' (length=35)
141:boolean false

Symptoms:
The function behaves as expected by returning true or false, but fields with keys including _level still appear in the translation editor when they should not.

Questions:
Why are fields with keys including _level still showing in the translation editor despite the function returning false?

March 11, 2025 at 6:44 am #16799480

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for contacting us.

1) May I ask why you are using this approach and not setting the field to be translatable or not from ACF group translation settings?

2) Did you make a small change to the default language page, save and then re-translate? It needs an update for ATE editor to start new job, otherwise ,it shows pthe revious job content.

Regards,
Drazen

March 11, 2025 at 10:18 am #16800730

michelleM-18

Hello! Thanks for getting back to me. Just to give a bit of detail around this problem:

1) We are using a PHP implementation for all ACF fields, and ACF fields are not created inside of WordPress, do not show up inside of the CMS.

2) I have "Cancelled Translation + Modified Content + Saved Post + Tried Translation Again".

- 2.1) Non of the ACF fields assigned to Gutenberg Blocks show up - in "Settings> Custom Fields Translation"

- 2.2) Additionally I have gone to "Languages > Edit Languages > Updated 1 value" to see if any updates are triggered.

---

I have double run each task mentioned above to double-check if it might resolve the issue, Again, every field shows in the WPML translation editor, rather than just the fields that return true. When running acfml_should_translate_acf_entity it does see every field, and run through them returning a value of either true or false based on the logic 🙂

I've attached an image, in effect the headings should not show as translatable content.

Screenshot 2025-03-11 at 10.17.47 AM.png
March 11, 2025 at 11:06 am #16801034

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

Thanks for getting back to me.

In that case, I would suggest using next method, and setting the correct translation settings inside your PHP code:

- https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/setting-the-translation-preferences-for-acf-fields-created-using-php-code/

Recommended translation settings for each filed type:
- https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/recommended-custom-fields-translation-preferences-for-acf-and-wpml/

Let me know if this is okay and how it goes.

Regards,
Drazen

March 14, 2025 at 9:38 am #16815503

michelleM-18

Hello!

Thank you, this seemed to work really well - however there is one more small issue I need to address with this way of proceeding.

Our standard Field Layout is like the following:

[
'label' => 'Alignment',
'name' => 'alignment',
'type' => 'select',
'choices' => [
'left' => 'Left',
'right' => 'Right',
],
'default_value' => 'left',
'required' => true,
'wpml_cf_preferences' => 1,
],

However when it comes to links, the translation editor is trying to translate the link and the link label, rather than just the link label.

Our links are often in a repeater field. For example:

[
'key' => $key,
'label' => $this->label,
'name' => $this->name,
'type' => 'repeater',
'layout' => 'block',
'button_label' => 'Add Button',
'sub_fields' => [
[
'label' => 'Link',
'name' => 'link',
'type' => 'link',
'wrapper' => ['width' => '50',],
'return_format' => 'array',
'wpml_cf_preferences' => 2, // WPML Set to translate
];
],
],

I've attached a screenshot, showing the button URL showing up in this instance - in which we'd only like to translate the Label.

Screenshot 2025-03-14 at 9.37.31 AM.png
March 14, 2025 at 11:16 am #16816237

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for getting back.

I am afraid it is expected, and correct would be that WPML automatically adds a translated link.

Currently, it is a known issue, and we are planing fix for ACFML 2.2.0.

In the meantime you can translate them manually or try next suggested workaround:

- https://wpml.org/forums/topic/i-need-help-with-translating-acf-link-field-in-advanced-transltion-editor/#post-16709536

Let me know if that helps.

Regards,
Drazen