Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
If you're experiencing issues where related posts in the API still appear in the original language despite having translations, and your code works locally but not on the live site.
Solution:
We recommend you follow these steps:
1. Navigate to WPML-> Languages.
2. Select 'Different languages in directories' in the Language URL Format section.
3. Save your changes.
4. Resave the permalinks.
5. Check the translated endpoint with '/en/'.

If this solution does not resolve your issue, or if it seems outdated or irrelevant to your case, please open a new support ticket. 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, you can also 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.

Tagged: 

This topic contains 16 replies, has 2 voices.

Last updated by Osama Mersal 3 months ago.

Assisted by: Osama Mersal.

Author Posts
August 14, 2024 at 10:05 pm #16072562

timH-49

Background of the issue:
On our website, we have repeater fields which are repeating post objects. When we add items (posts) to the repeater, they are not shown in the already existing translation. The ACF field group is set to: Same fields in all languages. The WPML setting is set to 'copy'. There are 6 'promotion' fields because we added 6 objects to the repeater after creating the initial translation of the post. It works on my local machine but we cannot reproduce the same settings on production. What also may be important: The posts that are added to the repeater also need to be translated (and most of them are).

Symptoms:
When we open the post in the original language and the translation, we only see the repeater items that were there from the beginning, not the ones we added after creating the translation.

Questions:
Why are the repeater items added after the initial translation not shown in the translation?
How can we ensure that new repeater items are copied to the translation?
Are there any specific settings in WPML or ACF that we need to adjust to fix this issue?

August 15, 2024 at 9:52 am #16073822

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Thanks for contacting WPML forums support. I'll be glad to help you today.

I would need to look closely at your site, so I would need to request temporary access (WP-Admin and FTP)
Preferably to a test site where the problem has been replicated.

Your answer will be private, meaning only you and I can access it.

❌ Please backup your database and website ❌

✙ I need your permission to deactivate and reactivate the plugins and themes and change site configurations. This is also why the backup is critical.

✙ I also need your permission to take a local copy of your site to debug the issue without affecting your live site.

Best regards,
Osama

August 15, 2024 at 10:56 am #16074039

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Thanks for the access details. I checked the module post and was able to fix the issue by deleting one row, updating the post, re-adding the row, updating the post, and updating its translation.

Kindly check if hidden link">it's working as expected.

Best regards,
Osama

August 15, 2024 at 11:13 am #16074048

timH-49

Thanks, it definitely works better now. All repeater rows (posts) are present, in the original language and translation.

BUT in the API the related posts are still in the original language, even though they have a translation. The code works locally, this is how I build the response object:

```php
$id = $request->get_param('id'); // The ID is the post ID of the original language, or the different post ID of the translation
$portal = get_post($id);

$moduleSlug = $request->get_param('module');
$module = get_page_by_path($moduleSlug, OBJECT, 'module'); // This post ($module) is translated correctly, all fields are in the original language or translated language

$module->blocks = array_map(static function ($block) {
return $block['block'];
}, get_field('blocks', $module->ID) ?? []); // "blocks" now contains the correct related posts from the repeater field, unlike before, but just in the original language, not in the translation of $module.
```

August 15, 2024 at 11:43 am #16074175

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

I edited the "single-module.php" file and commented on all of your code to check the output when looping on the repeater field on my local installation.

I added this code, and the result was that the posts appeared translated correctly. (Kindly check the attached screenshot)

Best regards,
Osama

2024-08-15_14-37-41.jpg
August 15, 2024 at 12:41 pm #16074361

timH-49

That is good to know that it can work, thanks!

That may work in your example because the post (module) is loaded in the main query. But how do you get the translated posts if you do not have a main query, e.g. with `get_field('blocks', $module->ID)`?

By the way, the code I am posting at the moment is from the active theme "rest/index.php"

August 15, 2024 at 2:49 pm #16075077

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Thanks for your update. Please check the following and confirm that I understand the issue correctly.

I used this code to get the posts:

  • EN: hidden link;
  • DE: hidden link;
  • The posts are shown correctly, along with their IDs in both languages

The REST endpoint shows the following results:

  • EN: hidden link;
  • DE: hidden link;
  • The blocks and promotion IDs are not translated in English

I'll consult our 2nd tier support team regarding this issue and update you with their findings.

Best regards,
Osama

August 15, 2024 at 2:54 pm #16075091

timH-49

The first part is correct. For the second part:

We wrote a separate endpoint for the rest API, see the code above or the `rest/index.php` file. The URLs would be:

* Default: /wp-json/wp/v2/portal/195/module/innere-staerke
* EN: /en/wp-json/wp/v2/portal/195/module/psychological-resilience-bi

The code in question:

```php
$module->blocks = array_map(static function ($block) {
return $block['block'];
}, get_field('blocks', $module->ID) ?? []);

// Append the featured image to each block
$module->blocks = array_map(static function ($block) {
$block->acf = get_fields($block->ID);

return $block;
}, $module->blocks);
```
Where $module->ID is 439.

August 15, 2024 at 3:00 pm #16075097

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Sorry for the confusion, but the custom endpoint shows the translated IDs. (hidden link)

Please let me know if I'm missing something and share a screenshot from the sandbox site. You can log in to this sandbox site using the access details you provided me.

Best regards,
Osama

August 15, 2024 at 3:03 pm #16075132

timH-49

In your sandbox, yes. In our production environment, no.

That is what I initially thought, that everything is configured correctly but there is some kind of weird bug that you have to remove and add something again to fix this. I don't know.

August 15, 2024 at 3:06 pm #16075147

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

I see the same on your site but without the /en/. (hidden link)

Please try the following steps:

1- Go to WPML-> Languages
2- Select "Different languages in directories" in the Language URL Format section
3- Save
4- Resave the permalinks
5- Check the translated endpoint with /en/

Best regards,
Osama

August 15, 2024 at 3:08 pm #16075164

timH-49

Thanks, that was it. Alternatively, that's what I did, was to append "?lang=en" to the URL.

August 15, 2024 at 7:56 pm #16076074

timH-49

Sorry, but the issue isn't resolved yet. The structure is as follows (all custom post types with m<->n relationship in acf repeater fields): portal -> module -> block

While the portal and module are now translated, the blocks are not. I guess this is the same error as above with the module where you said:
> I checked the module post and was able to fix the issue by deleting one row, updating the post, re-adding the row, updating the post, and updating its translation.

The module title is translated, but from the method get_field('blocks', $module->ID) I get back "false" instead of the fields. This is also visible in wp-admin, because if I look at the module in the default language, it has fields, in the translated language it has lock icons but no fields. The examples in the screenshot are block 120 (de) and 441 (en).

But I do not want to re-add or remove some fields every time I edit something. Isn't acf officially supported?

Screenshot 2024-08-15 at 21.55.00.png
Screenshot 2024-08-15 at 21.54.32.png
August 15, 2024 at 8:05 pm #16076133

timH-49

Yeah, I could confirm the issue. If I add another field to the original language (post type block), save it, delete it again, save it, and then edit the translation, all fields are there, untranslated. Just like you did with the module post. Do I have to translate everything again, or why does WPML not recognize that these fields were previously translated? Where are the translations gone?

August 16, 2024 at 11:09 am #16078072

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

1) Did you move or copy your site after translating the existing translation?

2) Could you please try the following test:

1- Create a new test block
2- Translate it
3- Make an edit the the default language block
4- Update the translation

Kindly let me know if you see the previously translated strings correctly in the translation editor.

Also, please let me know if the updates appear correctly on the translated block post in the dashboard.

Best regards,
Osama