Home›Support›English Support›[Resolved] ACF Extended Dynamic Preview not working on WPML non-primary language with the Advanced Custom Field...
[Resolved] ACF Extended Dynamic Preview not working on WPML non-primary language with the Advanced Custom Field...
This thread is resolved. Here is a description of the problem and solution.
Problem: You are facing issues with ACF Extended Dynamic Preview not working correctly in WPML's non-primary languages. Specifically, calls to
get_field('[field-name]', 'option')
do not function as expected in dynamic previews, and translated texts using
__(...)
do not render in the correct language. Solution: This behavior is expected due to the admin language being different from the current (secondary) language. WPML loads strings in the admin language by default. When you enable or disable the preview, the plugin performs an AJAX request to render the preview, during which the string gets translated by ACF Extended. To resolve this, go to your user profile and select the 'Set admin language as editing language' option. With this setting enabled, the strings should translate correctly.
If this solution does not resolve your issue, or if it seems outdated or irrelevant to your specific case, we recommend opening a new support ticket. Additionally, 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. For further assistance, please visit our support forum 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 resolve an issue with ACF Extended Dynamic Preview not working on WPML non-primary language with the Advanced Custom Field Multilingual plugin.
Here is a repeat of the workaround you provided, for convenience.
function wpml_translate_acf_post_id_compsupp_7448($preload, $post_id) {
// If the post ID is already set by previous filters, return it
if ($preload !== null) {
return $preload;
}
// Check if WPML is active and the post ID is set
if ( function_exists('wpml_object_id') && $post_id ) {
// Get the post type for the given post ID
$post_type = get_post_type($post_id);
// If a post type is found, apply the WPML filter to get the translated ID
if ( $post_type ) {
return apply_filters('wpml_object_id', $post_id, $post_type, true);
}
}
// Return the original post ID if no translation is needed or possible
return $post_id;
}
add_filter('acf/pre_load_post_id', 'wpml_translate_acf_post_id_compsupp_7448', 100, 2);
Symptoms:
The workaround provided has a few issues.
1. Dynamic previews often use acf to load to site-wide options, using get_field('[field-name]', 'option')... this no longer works inside a dynamic preview.
2. Translated texts loaded with __(...) do not render in the correct language inside the dynamic preview.
I can reproduce these problems on a new sandbox at your request (since the old sandbox is expired).
Questions:
Why are calls to get_field('[field-name]', 'option') not working inside the dynamic preview?
Why do translated texts loaded with __(...) not render in the correct language inside the dynamic preview?
Languages: English (English )French (Français )Arabic (العربية )
Timezone: Pacific/Easter (GMT-06:00)
Hello again,
Could you please reply back once you replicate the issue and if the issue replication steps are different than the initial ticket, please explain how to replicate it.
Languages: English (English )French (Français )Arabic (العربية )
Timezone: Pacific/Easter (GMT-06:00)
Hello again,
So our team would like to test this further,
To avoid further complications, could you please provide a step-by-step guide on how to reproduce the issue?
I understand that you already did that on the past ticket, however, since it has been a while since the last time we worked on this. It would be helpful to reopen this on a constant and clear description on how to reproduce this,
No need to re-explain the issue, I just need a step-by-step guide on how you reproduce this,
1. open the sandbox wp, and go in the Pages menu
2. switch the language to French (in the wordpress top bar)
3. open the page "Test page FR"
4. in Page Content, look at the Paragraph content block (it is a flexible content acf type, and uses ACF-extended Dynamic Render feature). The area with a dashed green border is the dynamic render preview, and shows a table with 3 rows :
- row 1 shows the value of a simple acf field, and works
- row 2 tries to show the value from an acf option field, and fails (problem #1)
- row 3 tries to show the value of a __() wp translated string, and show the english version of that string instead of the french version (it should show "FRENCH string"). (problem #2)
Interestingly, if you switch mode on the layout (by clicking on Paragraph content) and switch back to preview mode (by clicking it again), the row 3 then shows the correct translated string.
Languages: English (English )French (Français )Arabic (العربية )
Timezone: Pacific/Easter (GMT-06:00)
Hello again,
Just to confirm the first problem, I have disabled WPML and WPML ST on the sandbox, and yet, the option field is not working in English : hidden link
Could you please double check that? see if you could make it work on the default language first and then we could add it as a WPML issue,
In the meantime, our team are checking your second issue :
"Row 3 tries to show the value of a __() wp translated string, and show the english version of that string instead of the french version (it should show "FRENCH string"). (problem #2)"
Let me know if you find a way to make the option field work,
I've added a fix for row 2, it should now always work in english.
The fix was, I changed the code : get_field('option_1', 'option')
to : get_field('option_1', 'options')
(added an s to option)
Doing that, I've noticed 2 more problems, probably related in some way :
1. The value of row 2 is always in english.
If i disable the code fix wpml_translate_acf_post_id_compsupp_7448 (in functions.php), the value of row 2 work properly, and shows in the correct language.
2. The translation of the acf option pages (hidden link) doesnt work (always shows field values in english).
If i disable the code fix wpml_translate_acf_post_id_compsupp_7448 (in functions.php), the values of every field show (and saves) in the correct language.
I've disabled the wpml_translate_acf_post_id_compsupp_7448 fix for now, since it causes more problems than it solves.
I've noticed that with the fix disabled, everything works except row 3. Was an update pushed to WPML ?
Languages: English (English )French (Français )Arabic (العربية )
Timezone: Pacific/Easter (GMT-06:00)
Hello again,
Thank you for the follow-up,
As of the updates, We actually contacted ACF Extended authors about this and I suppose they implemented a fix from their side, the last detail I could find is that they confirmed that they found the issue from their side and that they will be working on it.
We are yet to receive a confirmation if the fix was implemented yet, I will keep you updated,
In the meantime, I have shared your new findings with our compatibility team to get a proper workaround,
Languages: English (English )French (Français )Arabic (العربية )
Timezone: Pacific/Easter (GMT-06:00)
Hello,
This turned out to be an expected behavior as the admin language is different than the current language (secondary language). Then:
- WPML always load strings in the admin language.
- When you enable/disable the preview, the plugin does an ajax request to get the preview rendered, and this time the string gets translated.
- This is done by ACF Extended.
Solution: Go to the user profile and select the Set admin language as editing language option. With this option enabled, the strings get translated correctly.
Best,
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.