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.