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.

Elementor users - please update WPML to the latest version to maintain compatibility. More details here - https://wpml.org/changelog/2024/12/wpml-4-6-15-critical-update-for-elementor-sites/

Tagged: 

This topic contains 0 replies, has 0 voices.

Last updated by Bruno Kos 1 day, 10 hours ago.

Author Posts
December 23, 2024 at 1:47 pm #16540621

justinV-10

Background of the issue:
I am using WPML in a multisite environment and encountering issues with the switch_to_blog() function. My setup includes the latest WordPress version, a multisite installation, and WPML active only on Blog 1. I have a simple plugin that inserts a post after switch_to_blog is called: function wpml_switch_poc_init(): void { $post_arr = [ 'post_title' => 'My very first post', 'post_content' => 'My very first post content', 'post_type' => 'post', ]; $blog_1_post_id = wp_insert_post( $post_arr ); var_dump($blog_1_post_id); switch_to_blog(2); $blog_2_post_id = wp_insert_post( $post_arr ); var_dump($blog_2_post_id); restore_current_blog(); } add_action('plugins_loaded', 'wpml_switch_poc_init'); WPML is not active on Blog 2, and I do not intend to activate it there.

Symptoms:
I expected no usage of WPML filters after switch_to_blog is made and WPML is not active in the target blog, with no error messages. Instead, I received a WordPress database error: Table 'db.wp_2_icl_translations' doesn't exist for query SELECT tra.term_taxonomy_id AS translated_id, IFNULL(corr.term_id, 0) AS correct_parent FROM wp_2_term_taxonomy org JOIN wp_2_icl_translations iclo ON org.term_taxonomy_id = iclo.element_id AND iclo.element_type = CONCAT('tax_', org.taxonomy) JOIN wp_2_icl_translations iclt ON iclt.trid = iclo.trid AND iclt.source_language_code = iclo.language_code JOIN wp_2_term_taxonomy tra ON tra.term_taxonomy_id = iclt.element_id LEFT JOIN wp_2_term_taxonomy parents ON parents.term_id = org.parent LEFT JOIN wp_2_icl_translations parent_lang ON parents.term_taxonomy_id = parent_lang.element_id AND parent_lang.element_type = CONCAT('tax_', parents.taxonomy) LEFT JOIN wp_2_icl_translations iclc ON iclc.language_code = iclt.language_code AND parent_lang.trid = iclc.trid LEFT JOIN wp_2_term_taxonomy corr ON corr.term_taxonomy_id = iclc.element_id WHERE org.taxonomy IN ('category') AND IFNULL(corr.term_id, 0) != tra.parent AND iclt.source_language_code IS NOT NULL made by require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('plugins_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, wpml_switch_poc_init, wp_insert_post, do_action('save_post'), WP_Hook->do_action, WP_Hook->apply_filters, display_tax_sync_message, do_action('wpml_new_duplicated_terms'), WP_Hook->do_action, WP_Hook->apply_filters, new_duplicated_terms_filter, WPML_Term_Hierarchy_Duplication->duplicates_require_sync, WPML_Term_Hierarchy_Duplication->get_need_sync_all_terms, WPML_Hierarchy_Sync->get_unsynced_elements. WPML filters remain active after using switch_to_blog() despite the plugin not being active on Blog 2.

Questions:
Why are WPML filters still active after using switch_to_blog() when WPML is not active on Blog 2?
How can I prevent WPML filters from affecting Blog 2?

December 24, 2024 at 10:19 am #16543260

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

Hi,

I created a multisite here:
hidden link

And also setup few sites with WPML active.

Logins are:
hello@wpml.org
gE469ajqUY

I will send FTP in the next private reply.

Error logs are activated also.

Can you show us this error here and tell us how can we reproduce it? You can do within this network as you wish. We can check with our 2nd tier then.