This thread is resolved. Here is a description of the problem and solution.
Problem:
After updating to a version of ACFML greater than 2.0.5, you might find that on a secondary language page, many ACF fields (e.g., from an ACF options page) and unfilled fields in the backend are saved in the postmeta. This results in numerous empty fields and incorrect
get_field()
calls because the field is present with the post but has an empty array as a value. In the default language, these fields are not saved in the database.
Solution:
We recommend editing the file
\sitepress-multilingual-cms\classes\custom-field-translation\class-wpml-copy-once-custom-field.php
. On line 36, replace:
$custom_fields = get_post_meta( $post_id );
with:
$custom_fields = get_post_meta( $post_id ); $custom_fields_to_copy = array_intersect(array_keys((array) get_post_meta( $source_element_id )), $custom_fields_to_copy);
This change should resolve the issue. Additionally, ensure that each of your custom fields across different field groups has a unique Field Name to avoid translation and functionality issues. More details can be found in the WPML documentation.
If this solution does not apply to your case, or if it seems outdated, please open a new support ticket. We also 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, you can always contact our support 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: Bug
This topic contains 26 replies, has 2 voices.
Last updated by Andreas W. 5 months ago.
Assisted by: Andreas W..
Author | Posts |
---|---|
May 16, 2024 at 9:09 am #15633954 | |
sissiB |
I am trying to: save a post in the secondary language Link to a page where the issue can be seen: hidden link after updating to a greater version of acfml than 2.0.5 I have the issue that on a secondary language page a lot of acf fields (from an acf options page for example [fields page_*, button, client, clients,..] and not filled out fields in the backend like "kunden" are saved in the postmeta which results in a lot of empty fields and then wrong get_field() calls because all of a sudden the field is there with the post but has an empty array as value. in the default language those fields are not saved in the database (default lang is german screenshot with -de-), you will see the difference in the results (63 entries in DE and 82 in EN). Something with saving a post in secondary language is not working correctly. |
May 16, 2024 at 9:27 am #15634107 | |
Andreas W. Supporter Languages: English (English ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
Hello, ACF Options pages can only get translated while switching the language inside the top admin bar, which means to translate them, the fields need to have a value in each language. Usually, by default, the fields should get copied but it might be that you are using a different setting for the field group- Which settings does the field group use? If it is Expert mode, also add the setting information for the fields. Also, please verify that the post type ACF Field Groups should be set to "Not translatable" at WPML > Settings > Post Type Translation. Best regards |
May 16, 2024 at 10:32 am #15634460 | |
sissiB |
hello andreas, you are not understanding correctly: I am saving a custom post type (or page) that has acf fields. But on saving the post in the secondary language, I get in the database also fields saved to this post (the custom post type) that are fields from the options page and also empty entries from fields that are attached to this post which should not be saved there. all field groups (trough the page) use expert settings. something in the behaviour of saving in the seconday language changed with the acfml update. best, |
May 16, 2024 at 11:02 am #15634604 | |
Andreas W. Supporter Languages: English (English ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
I will try to recreate this issue on a new test site and then get back to you. |
May 16, 2024 at 12:11 pm #15634894 | |
sissiB |
Thank you. Best, |
May 16, 2024 at 3:53 pm #15636117 | |
Andreas W. Supporter Languages: English (English ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
This does only occur on the CPT? How is your CPT created? Do your field groups use any ACF PRO fields, like Repeater Fields for example? Could you please assist in trying to recreate the issue on the following test site? One-Click-Login: If ACF PRO is needed I would appreciate you install the plugin and then import your field groups. You will find access to the database at Tools > WP Adminer. Please leave me a message on this ticket once you are done with this task. |
May 16, 2024 at 8:37 pm #15637104 | |
sissiB |
I copied the fields to the site. I could reproduce the issue. after creating a post on "page one" in english the database saves the fields that are filled out and is ok ('select * from wp_postmeta where post_id = 139') after that i "duplicated" to german, then "translate indipendent", edited some fields and updated the german version - in there you see, that are a lot of acf fields that are either empty (or not filled out) in the post itself and fields from the options page, that are there as well ('select * from wp_postmeta where post_id = 172'). eta: for post_id 172 (de translation) what worries me here are the fields with meta id from 240-249) - these should not be there at all |
May 16, 2024 at 8:49 pm #15637122 | |
Andreas W. Supporter Languages: English (English ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
Thank you, I will run some tests and then get back to you. |
May 16, 2024 at 11:35 pm #15637243 | |
Andreas W. Supporter Languages: English (English ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
If you save a page, then all the fields will be saved to the database, no matter if they have a value to not. This is not a WPML issue, I can confirm the same behavior if I test the site without WPML. To avoid issues with empty fields, check if the field is empty before calling it. <?php if (get_field('field_name')) : ?> <p>My field value: <?php the_field('field_name'); ?></p> <?php endif; ?> After that, usually, the same registered fields should be used, if you update a field value on the original content. Anyhow, I can still confirm an issue here, testing without WPML. My original page has the ID 190 but anytime I edit a field and save the page again it creates a new ID entry on the mostmeta table, like 191, 192, etc. This does occur when WPML is disabled, which means that the reported issue is not WPML-related. --- If you translate the page then WPML will need to create some reference entries for the fields and it will then save the actual translations on our string tables. |
May 17, 2024 at 8:50 am #15638140 | |
sissiB |
Hi Andreas, we are still not talking about the same thing here. Your example is fine with wpml disabled, that is quite ok how it turns out, because the fields (that are not filled out) are really empty in the database, this would be fine by me. see screenshot pid190-nowpml I have again enabled wpml and created a new page (old ones weren't there anymore), with page id 193 ("test en"). After saving this page it looks good in the database (screenshot pid193-wpml-en). Eventhough not all fields are saved (filled out ones are there, but empty ones are not all there, which is fine, since they are empty I do not care, if they are there or if they are there and empty. Though you might want to consider that something is not really working anyways. Field with the name details_mail for example is not in the postmeta table (it is not filled out, but in your post id 190 it is there and empty, in my page (default lang) 193 it is not there at all, other fields like "details_place" are also not filled out, but in the database. Now coming to the translated page with id 195: you will see that fields until id 915 are ok (screenshot pid195-wpml-de), after that there the following fields, that are acf fields from the acf options page ("theme settings"): url, page_service, page_clients, page_contact, page_news, page_team, page_jobs => they have nothing to do with the post type page, and are set to appear on the options page (see screenshot acf-options). Now the fields "leistungen", "kunden", "end_personen" => those 3 are fields that are in the field group for the post type "page" - all those 3 are empty in the backend, and not filled out, but they are not saved empty in the dabase, they havea an emtpy array in there "a:1:{i:0;s:0:"";}" which is wrong. Because either they are empty and have no value in there or have a value, but not am empty array. Also you see those fields are not in the originl post (195). With that I hope you know understand the issue, because if in the template I now check for get_field('leistungen') which is empty, I get a true for the translated page (which should not be) and false for the original language (which is ok). If I downgrade to acfml 2.0.5 this issue does not appear when saving translated pages. Thank you, |
May 17, 2024 at 5:36 pm #15640628 | |
Andreas W. Supporter Languages: English (English ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
Thank you, I can see the issue now. This needs some further testing, as I need to try to recreate the issue from scratch on new groups and verify in which use cases the issue occurs. It seems to be related to the Post Object Field. |
May 18, 2024 at 12:04 am #15641220 | |
Andreas W. Supporter Languages: English (English ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
Thank you for reporting this issue. This seems to be a bug that has existed since ACFML 2.1.0. I have escalated the issue now internally and I will get in contact with you once I have news from the team. |
May 28, 2024 at 6:22 pm #15680307 | |
sissiB |
Hi Andreas, |
May 28, 2024 at 7:01 pm #15680506 | |
Andreas W. Supporter Languages: English (English ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
Hi Sissi, Yes, it looks as if we handled a related issue with ACFML 2.1.3. Could you please update the add-on and test if the issue persists? If this will not solve the issue, please let me know. Best regards |
May 31, 2024 at 8:31 am #15691159 | |
sissiB |
Hi Andreas, It seems this is happening within flexible content with the acf type: "link" |