Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
You are trying to ensure that when you edit the status of the original Dutch post on your site, the translated English page automatically reflects the same status (Published, Draft, Private). However, the translated English page does not automatically update to have the same status as the original Dutch post.
Solution:
We recommend using a code snippet to synchronize the status across different language versions of your posts. You should add the following code to the

functions.php

file of your theme:

function sync_publish_status_across_languages($post_id) {
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
    if ('post' != get_post_type($post_id)) return;
    $post_status = get_post_status($post_id);
    $default_language = apply_filters('wpml_default_language', null);
    $translations = apply_filters('wpml_get_element_translations', null, $post_id, 'post');
    foreach ($translations as $lang => $translation) {
        if ($lang === $default_language) continue;
        $translation_post_id = $translation->element_id;
        wp_update_post(array(
            'ID' => $translation_post_id,
            'post_status' => $post_status
        ));
    }
}
add_action('save_post', 'sync_publish_status_across_languages');

Please note, this solution applies only to pages and posts. Ensure you have a full website backup before implementing this code.

If this solution does not resolve your issue or seems irrelevant due to being outdated or not applicable to your 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 needed, please open a new support ticket at WPML support forum 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 contains 1 reply, has 0 voices.

Last updated by Lucas Vidal de Andrade 1 week, 3 days ago.

Assisted by: Lucas Vidal de Andrade.

Author Posts
February 3, 2025 at 3:09 pm #16663487

arnoldV-2

Background of the issue:
I am trying to ensure that when I edit the status of the original Dutch post on my site hidden link, the translated English page automatically reflects the same status (Published, Draft, Private).

Symptoms:
The translated English page does not automatically update to have the same status as the original Dutch post.

Questions:
How do we make this happen

February 3, 2025 at 6:24 pm #16664056

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

WPML does handle the status of each content in each language independently.

You could try using a code snippet, like the following example. If you save this snippets inside the function.php file of your theme and then save an original post or page, it should sync the status into all active languages.

function sync_publish_status_across_languages($post_id) {
    // Check if this is a valid post type and that the post is not being autosaved
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
    if ('post' != get_post_type($post_id)) return;
 
    // Get the current post status
    $post_status = get_post_status($post_id);
 
    // Get the default language
    $default_language = apply_filters( 'wpml_default_language', null );
 
    // Get all translations of the post in different languages
    $translations = apply_filters( 'wpml_get_element_translations', null, $post_id, 'post' );
 
    foreach ($translations as $lang => $translation) {
        // Skip the default language post (we don't want to update it)
        if ($lang === $default_language) continue;
 
        // Get the translation post ID
        $translation_post_id = $translation->element_id;
 
        // Update the publish status of the translated post
        wp_update_post(array(
            'ID' => $translation_post_id,
            'post_status' => $post_status
        ));
    }
}
 
add_action('save_post', 'sync_publish_status_across_languages');

Please note that the code above only applies to pages and posts. Make sure to have a full website backup before proceeding.