Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
Hello,
At WPML > Settings > Posts and pages synchronization you can enable:
- Copy publishing date to translations
When it comes to these options, WPML will always sync from original content to translated content, not the other way around.
About the Post status:
WPML doesn’t sync this field. If you publish the original, translations remain in their current status (often “draft” or “needs update”). This behavior is expected like this when it comes to most WPML users.
You could build a custom logic that would automatically also set the status for translations by combining this hook with WPML Hooks.
Example:
/**
* Synchronize post status across all WPML translations.
*/
add_action('transition_post_status', 'sync_translation_status', 10, 3);
function sync_translation_status($new_status, $old_status, $post) {
// 1. Prevent infinite loops and only run if status actually changed
if ($new_status === $old_status || (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)) {
return;
}
// 2. Check if WPML is active
if (!did_action('wpml_loaded')) {
return;
}
// 3. Get the element type (post, page, or custom post type)
$post_type = get_post_type($post->ID);
$element_type = 'post_' . $post_type;
// 4. Get the "Translation Group ID" (trid) for this post
$trid = apply_filters('wpml_element_trid', null, $post->ID, $element_type);
if ($trid) {
// 5. Get all translations for this trid
$translations = apply_filters('wpml_get_element_translations', null, $trid, $element_type);
if (!empty($translations)) {
// Temporarily unhook to prevent recursion
remove_action('transition_post_status', 'sync_translation_status', 10);
foreach ($translations as $translation) {
// Skip the post we just updated to avoid redundant DB calls
if ($translation->element_id == $post->ID) {
continue;
}
// 6. Update the translation status
wp_update_post(array(
'ID' => $translation->element_id,
'post_status' => $new_status,
));
}
// Re-hook for future operations in the same request
add_action('transition_post_status', 'sync_translation_status', 10, 3);
}
}
}
Note that these custom hooks would work for original content or translations. Even if you change the status of a translated post, it will update the status of the original post and all its translations.
You can save this snippet at the end of the functions.php file of a Child Theme or use it inside a Code Snippet plugin.
Thank you for the information about the wpml setting and the code snippet.
I have selected the At WPML > Settings > Posts and pages synchronization you can enable:
- Copy publishing date to translations.
That works !!
Concerning the post status that do not sync, I understand , but still it would be good to have this as a setting.
Let say you have 3 languages, and a ecommerce site. Your product becomes closed (custom post status). Then you have to go into each language set individually each post. Which is a lot of work. Imagine now you a lot of products that you need to change post status to closed.
Personnally, I think this should be a good setting / option to have.