This thread is resolved. Here is a description of the problem and solution.
Problem:
The client reported that after updating the
post_name
of a translated product, the permalink (URL) does not update to reflect the English version, even after trying to flush rewrite rules.
Solution:
We suggested using a custom function to ensure that when a post is duplicated in WPML, its permalink (slug) updates to match the original post's slug. Here is the function to add to your theme's functions.php file or a custom plugin:
function custom_wpml_set_duplicate_permalink($post_id) {<br /> if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {<br /> return;<br /> }<br /> $is_duplicate = get_post_meta($post_id, '_wpml_duplicate', true);<br /> if (!$is_duplicate) {<br /> return;<br /> }<br /> $original_post_id = apply_filters('wpml_object_id', $post_id, get_post_type($post_id), false, wpml_get_default_language());<br /> if (!$original_post_id) {<br /> return;<br /> }<br /> $original_post = get_post($original_post_id);<br /> $original_slug = $original_post->post_name;<br /> if ($original_slug) {<br /> remove_action('save_post', 'custom_wpml_set_duplicate_permalink');<br /> wp_update_post(['ID' => $post_id, 'post_name' => $original_slug]);<br /> add_action('save_post', 'custom_wpml_set_duplicate_permalink');<br /> }<br />}<br />add_action('save_post', 'custom_wpml_set_duplicate_permalink');
We also recommended testing this solution in a sandbox environment and recording the process using a tool like https://www.loom.com/ to better understand the issue.
If this solution does not resolve your issue, or if it seems outdated or irrelevant to your case, please check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. We highly recommend opening a new support ticket for further assistance.
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.
This topic is split from https://wpml.org/forums/topic/theme-settings-not-working-after-wpml-update/
This topic contains 3 replies, has 0 voices.
Last updated by 3 months, 2 weeks ago.
Assisted by: Bruno Kos.