[Resolved] Advanced Custom Fields Radio Box Default Value Selection Issue
This thread is resolved. Here is a description of the problem and solution.
Problem:
The client has a custom post type called "Transaction" with an Advanced Custom Field of type Radio Button with options Yes and No. When using automatic translation, if the radio button is not selected in the original item, WPML incorrectly selects "Yes" in the translated version, allowing it to bypass required fields. This causes issues as the site relies on the Yes/No selection to determine if further fields should be present.
Solution:
We recommend setting all your groups to "Same fields across languages" in "ACF > Field Groups" to use the default configuration for each field type. This usually meets most clients' needs, with text fields being translatable and checkbox fields being copied.
If you need to fine-tune the translation preferences, switch to "Expert" mode for a particular group. You can then see and change the translation preference for each field.
You can find the recommended preferences for each field type here: Recommended Custom Fields Translation Preferences for ACF and WPML
On my site, a custom post type ("Transaction") is using an Advanced Custom Field of type Radio Button. (See attachment "field-group.jpg")
There are two options: Yes and No.
No is the default option and the field is NOT required.
When I translate using automatic translation, it appears that if the radio button is not selected in the original item, WPML is choosing "Yes" in the translated version, which then allows it to save blank fields for all of the required/dependent fields (see attachment "result.jpg"), which is something that couldn't happen if the item were translated manually because the browser would detect the missing required fields.
This currently breaks the site because I rely on that Yes/No selection to determine if further fields should be present.
QUESTIONS:
Is there a way to make WPML NOT fill-out this radio box if the original item doesn't have a value saved for it?
If not, is there a way to force WPML to choose the Default value, which is what I would expect?
Welcome to the WPML support forum. To help speed up the support process, I've enabled a private message for submitting the debug information for this support ticket. Please follow these initial debugging steps: https://wpml.org/faq/provide-debug-information-faster-support/
In short:
- Go to "WPML > Support > Debug Information" (link)
- Copy the Debug Information from there.
- Find the private field I activated and paste that information.
---
This file will allow me to check the translation preferences of your fields and see if they are set up correctly. This field should be set as "COPY", that way it will always match your selection from the original language.
Last, I see from the screenshots that you're editing the translation in the WordPress editor. Could you please also indicate your workflow? You mentioned automatic translation, so that means you're using our translation editor. I'm not sure why you're switching to the WordPress editor. (Could be just to see the error but I want to make sure it's not a workflow related issue as it's not recommended to switch editors).
Thanks for the debug info.
- I see that you have our add-on "Advanced Custom Fields Multilingual" installed
- And yes the translation preference is incorrect ("Don't translate" instead of "Copy")
What intrigues me is that on the screenshot you shared in your first answer (hidden link), I don't see translation preferences, so it means that you're not using the "Expert" mode and if you were using the "Same fields accros languages" mode, that field would have been set to "Copy" by default.
You can change the translation preference in "WPML > Settings > Custom Field Translation" but I would recommend that you go to "ACF > Field Groups" instead. Then edit your group and select the "Same fields across languages" option in "Multilingual Setup".
That way all your fields will be configured with our default settings.
Once the change made, please make a small change on a post in the original language (like adding a space at the end of the post title). Save changes, and then enter the translation to re-validate it. This should be enough to apply the new translation preference.
What I've experienced with adding WPML to an existing site is that "Translation Option" is not set to anything by default upon installing WPML and the ACF Multilingual plugins. (See "ACF Screen.png" attachment)
Should I be setting all of these to "Same fields across languages" by default, rather than leave them blank?
If so, I will do that, and then go through my field sets looking for required radio button sets to make sure they're set to "Copy" to prevent this issue in the future.
Yes, that what I would recommend to do:
- Set all your groups to "Same fields across languages". This will use our default configuration for each field type. For example all text fields will be translatable while checkbox fields will be copied. This configuration fits clients' needs most of the time.
- After that, if you want to fine tune / adjust some translation preferences, you can switch to "Expert" mode for a particular group. You will then be able to see the translation preference of each field and change it.
You can change the translation preference of most fields. For example, if you use a text field for the "author name". A name doesn't need to be translated, so you can switch to "copy" instead of "translate".
Now, some special fields need a specific preference, here I'm talking about layout fields such as "Repeater" or "Flexible Content". Those fields need to be "copied".
Thank you for all of your help. I have one more question before closing this ticket.
Here's the situation, which is essentially my situation and why I'm here.
I have an existing content type, let's call it "Products". The site has been around for a while so there are many existing Products in the system.
Today, I add a required radio button set with options of Yes and No to the Products post type.
Now, the existing Products can continue to exist without this radio button being checked either Yes or No, essentially being NULL. The only way existing Products will have this field filled-out is if someone edits the Product, in which case they will be unable to update the Product without selecting Yes or No.
However, if I were to install WPML and automatically translate all Products.... what happens with those existing Products with a NULL value for that field?
If I have the field in WPML set to "Copy" and the required field isn't filled-out, will the translated Product also have that field remain NULL?
I am assuming this is the case, and the reason my situation blew-up was because there was no setting for that field, in which case WPML chose ONE of the options by default... and I assume it chose the first option available which wasn't necessarily the one I set as required in ACF.
Unfortunately if the field is required WPML must add a value to be able to save the translation. But I think that if you set a default value for that checkbox in "ACF > Field Groups" then you should be able to update your existing products in bulk using the WordPress "Bulk Action" button.
Go to "Products", then select all 20 products from that list. Use the bulk action dropdown and choose "quick edit". The quick edit box will open, don't change anything, and click "Update". That should be enough to edit the 20 products and they should get the default value added.
PS: using the "Screen options" menu at the top right of your screen you can increase the 20 of post from 20 to 100 and bulk edit 100 products at the time.
Thanks for your response. It's not a big deal, but it doesn't look like a Quick Edit of a post sets a custom field value, even if it's required and has a default in ACF. Honestly, it would surprise me if it did.
I will keep what I learned here in mind when creating code that involves this scenario.
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.