WordPress WPML Comments Filter Plugin


I admit, this post is a bit “off-topic”. Recently we migrated this blog from using qTranslate to WPML for publishing in German and English. Main reasons were much better updates and a cleaner separation.
But one feature was missing because of that: We want to have comments from both languages below the postings (which are now two posts, where they have been one before). WPML doesn’t support this out of the box, but we were able to do this easily ourselves.

Because we believe in Open Source, here the sourcecode of our comment-merging plugin. If required one could also make languages configurable, but we did not need that, and it would have introduced some more complexity.

WPML comment merging plugin on wordpress.org

Plugin Name: WPML comment merging
Plugin URI: http://wordpress.org/extend/plugins/wpml-comment-merging/
Description: This plugin merges comments from all translations of the posts and pages, so that they all are displayed on each other. Comments are internally still attached to the post or page they were made on.
Version: 1.3
Author: Fabian Lange
Author URI: http://blog.codecentric.de/en/2010/06/wordpress-wpml-comments-filter-plugin/
License: MIT
function sort_merged_comments($a, $b) { 
	return $a->comment_ID - $b->comment_ID;
function merge_comments($comments, $post_ID) {
	// get all the languages for which this post exists
	$languages = icl_get_languages('skip_missing=1');
	$type = is_page($post_ID) ? 'page' : 'post';
	foreach($languages as $l) {
		// in $comments are already the comments from the current language
		if(!$l['active']) {
			$otherID = icl_object_id($post_ID, $type, false, $l['language_code']);
			$othercomments = get_comments( array('post_id' => $otherID, 'status' => 'approve', 'order' => 'ASC') );
			$comments = array_merge($comments, $othercomments);
	if ($languages) {
		// if we merged some comments in we need to reestablish an order
		usort($comments, 'sort_merged_comments');
	return $comments;
function merge_comment_count($count, $post_ID) {
	// get all the languages for which this post exists
	$languages = icl_get_languages('skip_missing=1');
	$type = is_page($post_ID) ? 'page' : 'post';
	foreach($languages as $l) {
		// in $count is already the count from the current language
		if(!$l['active']) {
			$otherID = icl_object_id($post_ID, $type, false, $l['language_code']);
			if($otherID) {
				// cannot use call_user_func due to php regressions
				if ($type == 'page') {
					$otherpost = get_page($otherID);
				} else {
					$otherpost = get_post($otherID);
				if ($otherpost) {
					// increment comment count using translation post comment count.
					$count = $count + $otherpost->comment_count;
	return $count;
add_filter('comments_array', 'merge_comments', 100, 2);
add_filter('get_comments_number', 'merge_comment_count', 100, 2);


  • Amir Helzer

    Good solution.

    We didn’t include something like that in the plugin, but what you’ve implemented is just fine.

    You can use icl_get_languages to get the list of other posts in other languages (instead of hard-coding it) and then release as a plugin on wp.org.

  • Gas

    Hi Fabian,

    Thanks for the comment merging function for WPML.

    I tried to use it on a 3 language page under development, which has a Guestbook type of page, and should have merged comments in all the languages, but it doesn’t work after installing the plugin through WP admin. Should I put something in the functions.php file or comments.php?

    The link:

    THanks for your help.

    Best regards,

  • Gas

    Sorry, the link changed to :
    (because it’s now opened to widepublic)
    THe comment merging still doesn’t work though… I tried also to turn off the other plugins, reinstalling the comment merger, but nothing helped.


  • Gas

    Never mind, I made the comment merging with jQuery AJAX.


  • Juan de Flores


    Your plugin is great but is he merging COMMENTS for PAGE POST? I think no…
    I’ve installed, reinstalled, like 5x times until I realize this.

    Are you going to update it? Or have I made something wrong?

    Thank you!

  • Juan de Flores


    I’ve Not found the solution!

    I’d have the comments appear in all the languages for the posts AND for PAGES POST.
    I download the pluging “Wmpl Comment Mergin”, it works really good but only for “normal” posts. It doesn’t work for “PAGE POST”.

    The problem with the plugin is that it only merge the comments for “post” not for “page”.

    This is a post I wrote:
    (english) http://www.polyglot-abc.com/flashcards-ultimate-guide-1000-words/
    (spanish) http://www.polyglot-abc.com/es/flashcards-ultima-guia-1000-palabras/
    The plugin works great. The comments are in both languages.

    This is a Page I wrote:
    (english) http://www.polyglot-abc.com/why-is-it-impossible-to-become-polyglot/
    (spanish) http://www.polyglot-abc.com/es/por-que-es-imposible-hacerse-poliglota/
    The plugin doesn’t merge the comments because it’s a page.

    How to make the plugin works with “PAGES”?

    Thank you!

  • Fabian Lange

    Thanks for your comments. I released version 1.2 right now which merges also comments for pages. The code in this blog has been updated and the new version should appear on your wordpress update tab any moment.

  • Juan de Flores

    Thank you so much! Great plugin!

  • Gas

    Thanks, it works now!!


  • jessor

    just a heads up here:
    somehow call_user_func() has changed in newer php releases. you use it in line 45 of wpml-comment-merging.php and it will produce “Warning: Parameter 1 to get_post() expected to be a reference, value given in…” while displaying comment count in the themes.

    this will probably occur on all machines running debian and updating to squeeze’s php which just got released 😉

    a simple fix is to just write a condition like if($type=post) and call the functions directly.


    • Fabian Lange

      Oh how I hate those stupid PHP changes, you can hardly ever inline somethinge, and sometimes BC is really broken badly. I will put up a working version during the hour.

  • Patricia

    3. June 2011 von Patricia

    Hi, thanks for this plugin. It does offer a nice and clean solution. I just have one issue. I run my multiple languages on several domains. My comments count is ok but if I click the link for see the comments, nothing appears on my english version. My german version looks totally fine but my english version not. Can I send you a PM somehow to send you some URL for better understanding?


  • 3dolab

    Could you please confirm that it’s working with the latest 2.3+ versions of WPML?
    I can get the correctly merged comment_count but not the list.

    It seems there is a comments_array filter that prevents the visitors from seeing
    comments in other languages.
    Anyone already put his hands in the inc/comment-translation/functions.php?

  • Toine

    Hi there, thanks for your good work so far!

    However, your plugin isn’t working for me (yet). I’m using WPML 2.3.4 and want to merge all the comments on a guestbook page. I have the same issue as 3dolab, the comment_count is working, but only the comments of the current language show up? Any ideas or update soon?

  • Fabian Lange

    Sorry guys, but at the moment there is no way to make the plugin work with the newest wpml anymore.
    The comment filtering broke the display, as it prevents getting comments in any other than the current language.
    For this blog, we hacked it, so its working for us, but i cannot recommend that.

    • Toine

      Hi Fabian, thanks for your answer.
      Is it very difficult to hack it? And will you still be able to make updates on the WPML plugin after the hack?

      • Fabian Lange

        Hi Toine,
        there quite a few places in wpml which you would need to change. everything which hooks into the regular comment mechanism. you need to redo this after every wpml upgrade. i might find a new way to do this, but i really hope for wpml to get a switch to completely turn off the comment translation code.

  • Simon Wheatley

    We’ve got the comment merging working with the latest WordPress and WPML for all post types. I’ve posted about it on the WordPress support forums.

    Thanks for your work on this plugin, Fabian, it’s great!

  • Jan


    I’ve been trying to get this to work but without success.
    I’ve placed some echo’s in the code to see what’s doing what.
    The comment count is correct (comments of all languages summed up).

    but the comment merging isn’t working.
    – retrieving the languages codes of the languages currently not being displayed
    – it can get the postID of the current post in other language

    when it does the get_comments() function with the other lang PostID passed along it retrieves nothing 🙁 🙁 🙁
    when I hardcode postID to the current post in current lang it just loops the current comments x-1 languages.

    so the code seems to work for current language posts only.
    It seems that get_comments() does not want to retrieve comments of the same post in other lang.

    would appreciate a work-around / help if anyone knows how to fix this 🙂


    • Jan

      by replacing:
      $othercomments = get_comments( array(‘post_id’ => $otherID, ‘status’ => ‘approve’, ‘order’ => ‘ASC’) );

      $othercomments = get_approved_comments($otherID);

      I got it to work again! 🙂

      • Matthias

        29. March 2012 von Matthias

        Hi Jan!
        For me your solution only works as long as I am logged in as admin.
        Did you try it already logged out?

  • Fabian Lange

    Hi Jan,
    yeah I have to admit that it is in a hacky state right now. I am not very pleased with the way WPML interacts with comments. Glad you got it working!


  • Patricia BT

    Hi Fabian

    As your plugin is not working on latest WP or WPML, Harshad from WPML has made a slight modification, I listed it there in the 3rd comment

    maybe you can just update it in the WP.org repository?
    (or do you prefer not to do so because you are not pleased by the current code?)

    anyway, for me this plugin is a lifesaver so I thank you very much.


    • Fabian Lange

      Hi Patricia,

      so that patch is working fine? I will have a look and update the plugin. I kind of lost the interest, due to the upgrade policy and comments by wpml. we are running now on our own fork of wpml, which is not having these commercial translation offers hooked up everywhere.



Your email address will not be published.