Skip Navigation

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

Problem:

The client is using Advanced Custom Fields (ACF) with WPML and has set up the Advanced Custom Fields Multilingual. However, the field choices are not being translated in the frontend despite translating the labels in WPML>>String Translation. The features section with bullet points is not translated across all languages.

Solution:

We recommended using the

get_field_object

function instead of

get_field

to fetch the field data correctly. This change should allow the field choices to display the translated values.

Here is the modified code snippet to implement in the functions.php file of the child theme:

// Create shortcodes for individual fields without titles
function generate_individual_field_shortcodes_no_title() {
    // List of fields to create shortcodes for
    $fields = [
        'living_area',
        'views',
        'laundry',
        'bathroom',
        'kitchen_and_dining',
        'bedroom',
        'media_and_entertainment',
        'miscellaneous',
        'home_safety',
        'outdoor_spaces',
        'family-friendly',
        'parking_and_facilities',
        'languages_spoken',
        'nearby',
        'house_rules',
        'cancellation_prepayment',
        'refundable_damage_deposit',
        'payment_methods'
    ];
 
    foreach ($fields as $field) {
        // Dynamically generate shortcode callback for each field
        add_shortcode($field . '_list', function() use ($field) {
            ob_start(); // Start output buffering
 
            $fields = get_field_object($field); //Get field data
            $options = $fields['value'];
 
            // Display labels.
            if( $options ): ?>
            <ul>
                <?php foreach( $options as $option ): ?>
                    <li><?php echo $fields['choices'][$option]; ?></li>
                <?php endforeach; ?>
            </ul>
            <?php endif; 
 
             
            return ob_get_clean(); // Return the output and end buffering
        });
    }
}

add_action('init', 'generate_individual_field_shortcodes_no_title');

If this solution does not resolve your issue or seems irrelevant due to being outdated or not applicable to your 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. If further assistance is needed, please open 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.

Tagged: 

This topic contains 2 replies, has 1 voice.

Last updated by vladimirM-19 1 month, 1 week ago.

Assisted by: Bigul.

Author Posts
November 28, 2024 at 7:14 pm #16456764

vladimirM-19

Background of the issue:
I am using ACF and I setup the Advanced Custom Fields Multilingual, but my field choices are not getting translated. I translated the labels in WPML, but the fields in languages are not getting updated. Link to a page where the issue can be seen: hidden link

Symptoms:
Features section with bullet points should be translated across all languages. I get the values, but they are not translated across languages.

Questions:
Why are my field choices not getting translated in ACF with WPML?
How can I ensure that the fields are updated in all languages?

November 29, 2024 at 12:45 pm #16459562

Dražen
Supporter

Languages: English (English )

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

Hello,

Thanks for contacting us.

While you wait for my colleague to take over the ticket, let me try to help you with the issue quickly.

Can you please explain how are you showing ACF choice on your website, using PHP code or some plugin? Do you choose to show ACF value or label from field settings?

Does it work if you try using the default ACF code to show the label on the front?

- hidden link

Let us know how it goes.

Regards,
Drazen

November 29, 2024 at 3:03 pm #16460231

vladimirM-19

Hi Drazen,

Yes, It is implemented through Short code, and it is presented on the frontend. In the image you can see the values, but they are just not translated. So english is in all languages

Screenshot 2024-11-28 at 8.12.17 PM.png
December 1, 2024 at 5:12 pm #16463497

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Thank you for the updates. Please share more details about the following for a better understanding. It would be great if you could share a couple of screenshots.

It is implemented through Short code

Also, please fill in the private details fields after a full site backup. I would like to access the admin area of your site for further checking. Refer to the following links for more details about our private information sharing policies.

https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

hidden link

--
Thanks!

Bigul

December 3, 2024 at 5:57 pm #16473289

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Thank you for the details and login information. This requires further testing. Do you have a staging/dev site, a clone copy of the live site? It will help us to troubleshoot the bug without affecting the live site.

If not, please allow me to make a duplicator copy of your site using the Duplicator plugin (https://wordpress.org/plugins/duplicator/) for debugging the issue on my local server.

--
Thanks!

Bigul

December 3, 2024 at 6:46 pm #16473451

vladimirM-19

Hi Bigul,

I have a backup made, but feel free to setup Duplicator.

Regards,

Vladimir

December 4, 2024 at 4:23 pm #16478012

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hi Vladimir,

Thank you for the permission. I made a copy of the site, we will debug it further locally and get back to you as soon as possible. Please wait.

--
Thanks!

Bigul

December 9, 2024 at 3:58 am #16490826

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hi Vladimir,

Sorry for the late response, because of the weekend. After using the *get_field_object* function instead of *get_field*, I got the expected results in my local copy. Refer to this document and the attached images for more details - hidden link

Please try with the following code after a full site backup and let us know your feedback.

// Create shortcodes for individual fields without titles
function generate_individual_field_shortcodes_no_title() {
    // List of fields to create shortcodes for
    $fields = [
        'living_area',
        'views',
        'laundry',
        'bathroom',
        'kitchen_and_dining',
        'bedroom',
        'media_and_entertainment',
        'miscellaneous',
        'home_safety',
        'outdoor_spaces',
        'family-friendly',
        'parking_and_facilities',
        'languages_spoken',
        'nearby',
        'house_rules',
        'cancellation_prepayment',
        'refundable_damage_deposit',
        'payment_methods'
    ];

    foreach ($fields as $field) {
        // Dynamically generate shortcode callback for each field
        add_shortcode($field . '_list', function() use ($field) {
            ob_start(); // Start output buffering

            $fields = get_field_object($field); //Get field data
            $options = $fields['value'];

            // Display labels.
            if( $options ): ?>
            <ul>
                <?php foreach( $options as $option ): ?>
                    <li><?php echo $fields['choices'][$option]; ?></li>
                <?php endforeach; ?>
            </ul>
            <?php endif; 

            
            return ob_get_clean(); // Return the output and end buffering
        });
    }
}
add_action('init', 'generate_individual_field_shortcodes_no_title');

--
Thanks!

Bigul

2024-12-09_09h27_10.png
2024-12-09_09h23_12.png
2024-12-09_09h22_20.png
December 9, 2024 at 1:26 pm #16493138

vladimirM-19

Hi Bigul, amazing, resolved. Thank you