Home›Support›English Support›[Resolved] WPML + ACF supporting both WP Editor and WPML Translation editor
[Resolved] WPML + ACF supporting both WP Editor and WPML Translation editor
This thread is resolved. Here is a description of the problem and solution.
Problem: The client is developing a multilingual site using WPML and ACF (flexible content) and needs to handle the 'wpml_cf_preferences' differently based on the editor mode (WP Editor or WPML translation editor) for specific posts. They encountered issues with repeater fields not syncing correctly between translations depending on the translation mode used. Solution: We do not have a direct hook to dynamically change 'wpml_cf_preferences' based on the editor mode at the moment. However, you can check the editor mode used for translation by querying the 'editor' column in the 'icl_translate_job' database table or the '_last_translation_edit_mode' meta. Based on this information, you can programmatically set the 'wpml_cf_preferences'. For detailed guidance on setting translation preferences for ACF fields, refer to our documentation here: Setting the Translation Preferences for ACF Fields Created Using PHP Code.
If this solution does not apply to your case, or if it seems outdated, 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 issues persist, please open a new support ticket at WPML support forum for further assistance.
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:
Hello, we're trying to develop a multilingual site using WPML + ACF (flexible content). The vast majority of pages will be translated automatically (WPML translation editor + deepL). However, some will be translated manually (WP Editor). When registering an ACF field (via PHP) we're able to add wpml_cf_preferences attribute to instruct how this field should be handled. The problem is that we need to handle it differently depending on which editor (WP Editor/WPML translation editor) is enabled for some specific post. A good example is repeater field. wpml_cf_preferences should be set to 'Copy once' when WP Editor is enabled and 'Copy' when WPML translation editor is enabled to make sure repeater items are always in sync between translations.
Symptoms:
I was not able to find any hook that could override wpml_cf_preferences when e.g. post is being updated.
Questions:
How can we handle wpml_cf_preferences differently depending on which editor (WP Editor/WPML translation editor) is enabled for a specific post?
Hi Bobby, thanks for getting back to me. However, I'm not sure were on the same page. The main problem we're facing is the way WPML handles custom fields. I'll try to provide an example. Let's assume there is a custom repeater field named features with wpml_cf_preferences attribute set to 'copy once'. It works just fine in wp mode (Different Designs per language) - it copies the features once and then you'e managing them for each language separately. But let's say I have another page with this ACF field in ate mode. In this case 'copy once' doesn't work ok - it doesn't keep features in sync (e.g. new feature was added, it doesn't appear in other languages). I would expect wpml_cf_preferences parameter having value 'copy' for this field when page is in ate mode so that items are always in sync. I know there is a way to change the WPML settings for ACF fields in admin but it's stored in icl settings and is global isn't it? Basically, we need an ability to amend wpml_cf_preferences setting on page level (based on editor mode) or some filter allowing to override it when post is being saved and processed by WPML. I hope all above makes sense.
Yes, that's correct Bobby. We register our ACF fields via PHP code and set wpml_cf_preferences based on documentation you've mentioned. This morning I performed a one more test.
- I've created a basic 'features' ACF group with a repeater field (copy once, wpml_cf_preferences=3) containing one text field (translate, wpml_cf_preferences=2)
- Created a new page which is in ate mode by default (we use Translate Everything Automatically mode)
- Added some items to the repeater field - all good, all items were translated
- Added one more item - it has not been added to other languages (due to copy once setting)
As you can see the above setup doesn't work ok with auto translation on the other hand, it is suitable for wp ("Different Designs per language") mode. That's why we have a need to have wpml_cf_preferences value dynamic based on editor mode.
What we expect:
- Page is always in sync when it's in ate mode which doesn't work ok with the above setup. Basically, it's an issue with fields supporting variable number of items e.g. relationship, flexible_content, repeater, etc. as it breaks when e.g. new items are added (they don't appear in translations)
- Users can manage content for each language separately when in wp mode. This part works ok with the above setup
I hope all above makes sense and thanks for your help!
I would like to request temporary access (wp-admin and FTP) to your site to test the issue.
(preferably to a test site where the problem has been replicated if possible)
**Before we proceed It is necessary to take FULL BACKUP of your database and your website. Providing us with access, you agree that a backup has been taken **
I often use the Duplicator plugin for this purpose: http://wordpress.org/plugins/duplicator/
You will find the needed fields for this below the comment area when you log in to leave your next reply.
The information you enter is private which means only you and I have access to it.
NOTE: If access to the live site is not possible and the staging site does not exist please provide me with a duplicator package created with the duplicator plugin.
once I switch to 'copy' ATE works as expected (fields are in sync and translated ok). But then it breaks the wp (Different Designs per language) mode:
- Assume we have a page with some features added and 1:1 (structure wise) page in German to begin with
- Switched to German, added a new item and saved the post. Once it's saved the newly added item is gone
- Similar thing happens if I try to remove an item. Once page is saved and new empty item is appended to the end of the features list.
Basically, it tries to keep the number on items in sync with the main language. It works as expected from the config perspective but the issue is that the same config (wpml_cf_preferences value) doesn't work ok for both ATE and WP. Repeater like fields (repeater, flexible, etc.) should have wpml_cf_preferences set to 'copy' when in ATE mode and 'copy_once' when in WP mode to make it work as expected. That's why I asked for some hook that allows to override wpml_cf_preferences value provided in config on the moment the page is being saved.
Hi Bobby, I've tested it using 'translate' and it looks like it did a trick!!! I didn't realize 'translate' is applicable for repeater like fields. Many thanks for your guidance 😉