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: Custom Work
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: Symptoms: Questions: |
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) 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, |
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, |
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 $moduleSlug = $request->get_param('module'); $module->blocks = array_map(static function ($block) { |
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, |
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:
The REST endpoint shows the following results:
I'll consult our 2nd tier support team regarding this issue and update you with their findings. Best regards, |
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 The code in question: ```php // Append the featured image to each block return $block; |
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, |
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 Best regards, |
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: 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? |
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 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, |