Skip Navigation

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: 

This topic contains 11 replies, has 2 voices.

Last updated by Subash Chandra Poudel 2 years, 1 month ago.

Assisted by: Subash Chandra Poudel.

Author Posts
March 15, 2023 at 11:31 am #13250607

michaelS-25

Hello there. I'm currently working on a multilingual site with ACF. I have a custom post type called "advisor" that has a relationship ACF field on it, referring to another CPT "product". This ACF field holds the products about which this advisor is an expert. The site's default language is Dutch. I'm translating the relationship ACF field to English automatically by using the "copy" option. The issue is as follows: when I select only one related product on the Dutch version of the advisor, the English version of the advisor will have the translated product correctly attached to it. However, in the database, the meta value is saved as a single ID, instead of a serialized array. This causes issues with the WPGraphQL plugin, because it expects a serialized array to be present as the meta value.

March 15, 2023 at 2:39 pm #13252637

michaelS-25

I've found another forum post where someone has a similar issue. They managed to fix it by manually changing the DB entries to save the values as a serialized array. In my case, the client whose website I'm building may change the relationship field any number of times, which will break the output each time they set a single value.

https://wpml.org/forums/topic/related-post-in-acf-not-correctly-displayed/

March 16, 2023 at 5:11 am #13256465

Subash Chandra Poudel

Hi there,

We apologize for the issues you are experiencing. WPGraphQL plugin is not yet officially compatible with WPML, so some issues may arise. However, in your case, the issue is due to the meta value for relationship ACF field being saved as a single ID in translation instead of serialized data.

This issue should not occur, and the relationship ACF field should be copied as serialized data in the translation. We previously received a similar report in a previous ticket you referenced (https://wpml.org/forums/topic/related-post-in-acf-not-correctly-displayed/) but latter found that the issue was specific to the client site, most probably due to interference from some third-party plugin or code.

If the translation of the Meta fields or CPT was done on your site before ACFML was installed/setup, we suggest trying the following:

- Edit the post with the issue and update it by adding an extra space or character in the title or content to trigger a translation update.

- Translate the post again and see if the Meta field is then copied as serialized data.

If this still does not work, we will need to troubleshoot further to see if this issue is coming from ACFML or not. We have set up a clean test site for you to use. Please login to the site using the next link and set up WPML, ACF, your CPTs, and Fields, and ACFML. Then, add and translate dummy/test posts to see if the issue is replicable.

hidden link

You can make use of plugins like https://wordpress.org/plugins/wp-phpmyadmin-extension/ to view the database content on the site.

Please let me know how it goes.

Best regards,
Subash

March 16, 2023 at 5:13 am #13256473

Subash Chandra Poudel

Also, along with the test results, to ensure the quickest and most accurate support, please provide your debug information so that I can get a look at some of your configurations. You can find it in WPML > Support > click on “Debug information” link. Please check this link for more info: http://wpml.org/faq/provide-debug-information-faster-support/

March 21, 2023 at 9:36 am #13291357

michaelS-25

I attached the debug information as requested for my local test site. However, I don't think you will need it, as I managed to reproduce the issue on the testing environment that you provided. Below is a description of what I did.

I installed the following plugins:
Classic Editor
ACF Pro
ACFML
WPGraphQL
WPGraphQL for ACF
WPGraphQL WPML

I set up WPML with English as the base language and Dutch as the only translation.

I created one ACF group called "Test group", which has one field "Test relationship". This group is shown on pages, and the relationship allows selecting one or more posts (only of the default "post" post type).

I created two posts "Test post" and "Test post 2" with only a title. I translated them to Dutch using the WPML Translation Editor, adding "(NL)" at the end of the translated title to better distinguish between languages.

I created two test pages "Test page" and "Test page 2".

On the first test page, I selected "Test post" as the only relationship, and translated the page using the WPML Translation editor, again adding "(NL)" at the end of the translated page title. Upon checking the English translation, I noticed that the relationship copied, but it hadn't selected the translated version of the relationship post. Instead, the English version (without "(NL)" in the title) was shown. Important to notice is that it is currently saved as a serialized array, and I can query it in WPGraphQL. I then re-saved the English page to trigger a translation update. Afterwards, the correct (translated) post was selected on the Dutch version of the post. However, the WPGraphQL no longer returns a post, because it is now saved as a single ID (in PHPMyAdmin, see the

wp_postmeta

table, and search for post ID 59).

This query can be ran in the integrated GraphiQL IDE on the test site, to show that the related post cannot be found by WPGraphQL because it is saved as a numeric ID instead of a serialized array:

query NewQuery {
  page(id: "59", idType:DATABASE_ID) {
    databaseId
    title
    locale {
      locale
    }
    testGroup {
      testRelationship {
        ... on Post {
          databaseId
          title
          locale {
            locale
          }
        }
      }
    }
  }
}

To show the difference between the once-translated and re-translated outputs, I created a second test page. On this page, I repeated the same steps as the first test page, but I stopped after translating it to Dutch once. On the PHPMyAdmin, if you look at the

wp_postmeta

table, and search for post ID 63 (the translated version of the second page), you will see a serialized array with a single element, which is the post ID 54. This is the ID of the English version of the second test post.

The code below is a query you can use to test the GraphQL output for the second page.

query NewQuery {
  page(id: "63", idType:DATABASE_ID) {
    databaseId
    title
    locale {
      locale
    }
    testGroup {
      testRelationship {
        ... on Post {
          databaseId
          title
          locale {
            locale
          }
        }
      }
    }
  }
}

I hope this clearly shows the situation, and will help you debug the ACFML plugin. To summarize what I think goes wrong here:

When an ACF relationship field (set to expert mode, copy) is initially translated, the exact contents of the original post are copied to the new post. This means the new post will have a relationship to the untranslated related post, but it will be correctly saved as a serialized array (because the contents are simply copy-pasted).

When updating the translation for an existing post, the translation step for the ACF relationship field works differently. The translated version(s) of the related post(s) is/are found, and then saved to the translated post, but if there is only one related post, the value is never converted to an array before saving, hence saving it as a single numeric ID, instead of a serialized array with a single value.

March 23, 2023 at 11:02 am #13314335

Subash Chandra Poudel

Hi there,

Thank you for your efforts in setting up the sandbox site and testing the issue there.

After further testing I am also able to replicate your case in a clean site, that relationship ACF field is nor translated properly in the first translation try and is stored as single ID in second and further translation tries.

I am escalated the issue to our Compatibility team, I will post an update here as soon as the team have an update regarding the team. Thank you for your co-operation and patience in the mean time.

Regards,
Subash

April 5, 2023 at 8:28 am #13407477

Subash Chandra Poudel

Hi there,

The issue has now been escalated to our developers for further checks.

In the mean time can you please try the following workaround and let me know if it helps fix the issue:

- Backup the site completely to prevent any issues.

- Edit the plugin file /wp-content/plugin/acfml/classes/class-wpml-acf-post-ids.php in your wordpress directory.

- In the line 8 find the following code:

$ids_unpacked = (array) maybe_unserialize($acf_field->meta_value);

- Replace it with:

$ids_unpacked = maybe_unserialize( $acf_field->meta_value );
 
$came_as_array = is_array( $ids_unpacked );

- Also in line 11 find the following code:

foreach ($ids_unpacked as $id) {

- Replace it with:

foreach ( (array) $ids_unpacked as $id ) {

- Save the file and edit the Page with the issue, update the page by adding an extra space or character in the title or content so as to trigger a translation update.

- Now edit the translation and complete it.

Please let me know how it goes.

Regards,
Subash

April 11, 2023 at 12:23 pm #13445705

michaelS-25

Hi Subash,

Sorry for the late reply. I only work two days a week and I hadn't checked the support ticket last week. The code you're suggesting creates a new variable

$came_as_array

, but that variable is never used afterwards. Could you confirm that that's intentional? I don't think these changes on their own will fix the issue. I feel like you forgot to include some of the necessary changes in your message.

Please let me know what the intended changes are and I'd be happy to try them out as a fix for the time being.

April 11, 2023 at 12:56 pm #13446025

Subash Chandra Poudel

Hi there,

The variable $came_as_array not being used anywhere is intended. I am suggesting this workaround as it seems to fix a similar issue previously, please let me know if it works for you or not.

As for the main issue, the issue has been escalated to our developers, we don't have an exact ETA for the fix however it might take some time for the fix as this seems to be an edge case issue. I will let you know of any updates from the development team as I get them.

Regards,
Subash

April 25, 2023 at 5:34 am #13530597

Subash Chandra Poudel

Hi there,

Any update on the workaround ?

Did it worked for you?

Regards,
Subash

April 26, 2023 at 10:48 am #13540365

michaelS-25

Hi Subash,

Sorry for the radio silence. I've had some other issues on my plate. I tried the fix just after posting my last message, but it unfortunately did not solve the issue for me.

I'll be looking forward to seeing the official fix.

April 26, 2023 at 3:28 pm #13542875

Subash Chandra Poudel

Hi there,

Thank you for the updates.

I have forwarded the details to our developers.
I will let you know as soon as I have an update from the team,

Regards,
Subash