This thread is resolved. Here is a description of the problem and solution.
Problem: The client is experiencing issues with translation connections not saving and resetting on subsites other than the main blog ID in a multisite environment. The issue arises when using a specific function in their theme that switches to the main site blog, queries for posts, and then restores the current blog. Solution: We explained that it is not possible to connect original content and translations between different subsites on a multisite network, as each subsite has its own tables and WPML language settings. This limitation is likely causing the observed issues with translation connections not being saved. If you're experiencing similar issues, we recommend reviewing the purpose and implementation of any custom functions that interact with WPML and multisite setups.
Please note that this solution might be outdated or not applicable to your specific case. 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. If the problem persists, please open a new support ticket.
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.
Background of the issue:
I'm having an issue with a function within our theme and WPML translations (connected translated pages). I have this code in our theme:
Thanks for coming back to me, this function is a snippet of a core function within our theme. Upon loading WP admin_int, it switches to blog 1, gets some data and switches back to the current blog.
This is causing an issue with WPML when editing subsite pages / translations. They disconnect on save and can't be reconnected.
I have a feel that us either switching blog and using the get_posts or WP Query is messing with WPML doing something at the same time.
For ease, I've spit the function into this snippet of code so that the problem can be recreated on any site.
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
You are trying to fetch attachments (here icons) from the main site and use them on another subsite of your multisite network?
Disabling this function will solve the issue with WPML?
I need to add again, that WPML can not handle content between different sites of a Multisite network, which might be the reason and this might be expected. I am just asking for confirmation what the main purpose or this approach is.
So yes, removing this function (this specific part) resolves the issue with WPML.
The main purpose of the function is to detect custom added icons which have been added on the main site. It all works independently of WPML. The icons "SVG" are detected and then saved into the database "options field" where they are later updated as options within an ACF field.
The problem is that if we run
switch_to_blog(1);
get_posts($args);
restore_current_blog();
Within the WordPress Hook "admin_init"
It seems cause problems with WPML linking translations.
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
WPML uses different language settings for each blog, and switching blogs manually can cause WPML's internal language context to be disrupted, leading to inconsistencies in language-specific content.
If you’re using WPML, the situation becomes even more complex because WPML needs to associate translations of attachments with the correct post on each subsite. Transferring attachments might break the translation relationships if not handled properly.
Please try this instead:
// Save the current WPML language
$current_language = apply_filters( 'wpml_current_language', NULL );
// Switch to the blog (1 in this case)
switch_to_blog(1);
// Optionally, make sure you're still on the same language
do_action( 'wpml_switch_language', $current_language );
// Fetch the posts
get_posts($args);
// Restore the current blog
restore_current_blog();
// Optionally, restore the WPML language setting if needed
do_action( 'wpml_switch_language', $current_language );
I have not tested this yet and I can not guarantee if this will solve the issue. Further, please take note that this request is usually out-of-scope for our support. We can only support features that are covered in WPML or open a feature request if possible, but what you are trying to do might simply not be possible with WPML, which is why I can not consider it a bug.
This doesn't appear to have worked. However, I understand that this may not be an issue directly with WPML. We'll review this further on our end to see if this can be resolved.