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 thread is resolved. Here is a description of the problem and solution.

The problem: User wanted comments from English posts to be shown on translations using "Post to translate Post" plugin.

The solution: There is an old php script that allows this: http://pastebin.com/SzmcRmx1.

Note: Watch out, this is not tested, so please handle with care. Note that the plugin is not longer maintained and could bring compatibility issues.

0% of people find this useful.

This topic contains 7 replies, has 4 voices.

Last updated by daniloN 4 years, 5 months ago.

Assigned support staff: Andrés.

Author Posts
May 12, 2015 at 9:05 am #616942

talitah

I am trying to: merge comments from Post to translate Post

I expected to see: comments from english post showing on translation of same post. I am looking for the correct working php file as noted here: https://wpml.org/forums/topic/same-comments-in-all-languages/

Instead, I got: no comments on my translated post. I also get a duplicated review and comments "transported" from blog post to

May 13, 2015 at 7:28 am #617667

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

Welcome to WPML support forum,

Here's what you ask for: http://pastebin.com/SzmcRmx1.

Watch out is not tested so please handle with care. Note that that plugin is not longer maintain and could be not compatible anymore.

Good luck,
Andrés

May 14, 2015 at 11:48 am #618768

talitah

Thanks for the link... the code works for adding comments to other languages.

I still have one problem however...

comments are duplicated to reviews areas on other pages where they do not belong. How can i keep comments linked to posts where they were created?

please see post_pg.png as attached previously

regards

May 14, 2015 at 1:52 pm #618908

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

- If you disable WPML comment merging plugin, does the comments remains duplicate?
- If you disable WPML multilingual plugin, does the comments remains duplicate?

I'll wait for your findings.
Andrés

May 31, 2015 at 9:13 am #629279

talitah

hi there

my apologies for the late reply...

if i disable WPML comment merging then problem of comments showing on reviews section is solved.

if i disable WPML multilingual plugin then my reviews section disappears as well as other features such as image gallery etc.

i have decided to remove the reviews area on the affected pages to avoid this problem. I need the duplication of post comments to translated pages, but cannot afford to have these comments displaying on review areas. This is a solid but temporary solution to the problem. I hope that the folks from WPML Comment merging will once again update their plugin to avoid this feature.

🙂 thanks for the assistance

regards

June 1, 2015 at 6:49 am #629461

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

Sorry for not being a better help.
Please, if you find a way to solve your issue, don't hesitate to share it with me.
Andrés

April 9, 2018 at 3:28 pm #1573559

René

Here's a possible solution. It's not tested because I took the snippet out of our codebase.

<?php

global $sitepress;
remove_filter('comments_clauses', array( $sitepress, 'comments_clauses' ), 10);
add_filter('pre_get_comments', 'my_pre_get_comments', 100, 1);

function my_pre_get_comments(\WP_Comment_Query &$wp_comment_query)
{
    if (($postId = $wp_comment_query->query_vars['post_id'])) {
        $postIds = [$postId];

        // get all languages
        $languages = apply_filters('wpml_active_languages', null, 'skip_missing=1');
        $type = get_post_type($postId);
        foreach($languages as $l) {
            if(!$l['active']) {
                $otherId = apply_filters('wpml_object_id', $postId, $type, false, $l['language_code']);
                if ($otherId) {
                    $postIds[] = $otherID;
                }
            }
        }

        // don't query for a specific post, instead query all language posts
        $wp_comment_query->query_vars['post_id'] = '';
        $wp_comment_query->query_vars['post_ID'] = '';
        $wp_comment_query->query_vars['post__in'] = $postIds;
    }
}

September 3, 2019 at 4:01 pm #4506101

daniloN

@René
You are a god! Thank you so much