Skip Navigation

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

**Problem:** I am having an issue with Advanced Custom Fields (ACF) on our website. We use `acf_add_local_field_group` function to manage fields, and I'm looking for a way to batch select all fields for translation. Manually selecting fields for translation is time-consuming due to the high volume of fields. I tried to find these entries in the database to create a script for automatic inclusion but couldn't locate the exact table where this information is stored.

**Solution:** To address the issue of batch selecting fields for translation in ACF, you can use the [WPML Compatibility Test Tools Plugin](https://wpml.org/documentation/related-projects/wpml-compatibility-test-tools-plugin/#how-do-i-generate-language-configuration-files-using-multilingual-tools) and the [Multilingual Tools Plugin](https://github.com/OnTheGoSystems/multilingual-tools). If the plugin is freezing due to the large number of fields, consider using the `wpml_cf_preferences` attribute in your field groups. You might write a script to add `'wpml_cf_preferences' => 2` to every field. For example, use a PHP script to read your ACF field configuration file, identify the lines where you need to insert the `wpml_cf_preferences`, and then write the updated content back to the file. However, note that this approach requires custom scripting and isn't part of the standard support scope.

**Relevant Documentation:**
- [Translating ACF Blocks with WPML](https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/translating-acf-blocks-with-wpml/#preparing-programatically-registered-fields-for-translation)
- [WPML Compatibility Test Tools Plugin](https://wpml.org/documentation/related-projects/wpml-compatibility-test-tools-plugin/)
- Multilingual Tools Plugin

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 3 replies, has 2 voices.

Last updated by Bruno Kos 1 year, 6 months ago.

Assisted by: Bruno Kos.

Author Posts
November 7, 2023 at 11:18 am #14746619

Nazar Kurnyk

Hello,

Our website is powered by Advanced Custom Fields (ACF), and we kick things off with the acf_add_local_field_group function. We're aware of the option to select fields for translation within the plugin's settings, but given the sheer volume of fields we're dealing with, it's quite a task. Is there a way to batch select all fields for translation instead?

We've attempted to locate these entries in the database to craft a script that would automatically include the fields, but we hit a roadblock as we couldn't pinpoint the exact table where this information is stored. Any guidance on this issue would be greatly appreciated.

November 7, 2023 at 11:30 am #14746653

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

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

Hi,

Thank you for contacting WPML support!

Would this help perhaps?
https://wpml.org/documentation/related-projects/wpml-compatibility-test-tools-plugin/#how-do-i-generate-language-configuration-files-using-multilingual-tools

So it is about using our hidden link plugin.

Regards,
Bruno Kos

November 7, 2023 at 2:10 pm #14747951

Nazar Kurnyk

Unfortunately, I have so many fields that the plugin freezes. Maybe there is some parameter that can be added to field groups?

Like I did 'action' => 'translate', to this field group (check attached image)

Знімок екрана 2023-11-07 о 16.09.47.png
November 9, 2023 at 9:02 am #14763459

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

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

There is this:
https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/translating-acf-blocks-with-wpml/#preparing-programatically-registered-fields-for-translation

So adding wpml_cf_preferences to individual fields. But I'm not aware of any of the options where these can be added in bulk for every field.

Perhaps you can write a script that would add 'wpml_cf_preferences' => 2, to every field, perhaps have the script do it before 'instructions' => '' e.g. something in these lines:

<?php
// Read the file content as a string
$file_content = file_get_contents('your_file.php');

// Define a regular expression pattern to match the required line
$pattern = '/required\'\s*=>\s*\d+,/';

// Define a replacement string to add the wpml_cf_preferences line before the instructions line
$replacement = "required' => 0,\n\t\t\t'wpml_cf_preferences' => 2,\n\t\t\t";

// Use preg_replace function to perform the substitution
$new_content = preg_replace($pattern, $replacement, $file_content);

// Write the new content to the file
file_put_contents('your_file.php', $new_content);
?>

But note this is not tested and is only a general idea and requires custom work that is not within the support scope.

November 13, 2023 at 10:43 am #14787369

Nazar Kurnyk

Ok, thanks. I'll try to use this option