Support » Plugin: Polylang » Multilang comment

  • I’m trying to display comment from a post in english inside one who is in french.

    $langage = get_locale();
    if($langage =="fr_FR"){
    $leid = $post->ID;
    					$leidt = pll_get_post($leid,$slug);
    					$comments = get_comments(array('post_id' => $leidt,'status' => 'approve','lang' => 'en,fr'));

    Unfortunaly nothing happening, i try replacing the $leidt by the post id, still nothing. but if i take the id of a post with the same lang the comment are returned correctly. Any idea how to disable filter ?

Viewing 10 replies - 1 through 10 (of 10 total)
  • I’ve try to force querying with.

    <?php 	$leid = $post->ID;
    					$leidt = pll_get_post($leid,$slug);
    					global $wp_query;
    					$comments = get_comments(array_merge($wp_query->query, array('post_id' => $leidt,'lang' => 'fr,en')));
    		//Display the list of comments
    			wp_list_comments(array( 'callback' => 'Futuristica_comment'), $comments);
    		echo $leidt;

    but so far northing

    Plugin Author Chouby


    You are fighting against Polylang and Polylang is winning 🙂
    There is a filter on comments to load only those in the current language. Up to now get_comments does not recognize the parameter ‘lang’.

    I have modified the current development version so that something like this should work:

    $comments = get_comments(array('post_id' => pll_get_post($post_id, $slug), 'status' => 'approve', 'lang' => $slug));

    get_comments will now load the comments in the languages specified by the ‘lang’ parameter, the current language otherwise. Let me know if it works as you expect.

    Of course, the other possibility is of course to disable the comments filter (todo after ‘wp’, priority 5):

    global $polylang;
    remove_filter('comments_clauses', array(&$polylang, 'comments_clauses'));

    If the task at hand is to display merged comments threads from all language versions of a post / page below every language version, I discovered that removing polylang’s comments_clauses filter together with the WPML Comment Merging plugin works very well.

    That plugin is meant for WPML, not Polylang, but because of their similarities this works amazingly well. Never found a hack like this … it’s like trying a random key and it opens the door 🙂

    Instructions (tested with WordPress 3.5.1):

    (1) Install and activate the WPML Comment Merging plugin.

    (2) Apply these two patches to wp-content/plugins/wpml-comment-merging/wpml-comment-merging.php. For me, with just two languages and just posts it worked without them, but they did not hurt either.

    (3) Into functions.php of your template or child template, add this to remove the polylang comments_clause filter (because else, the correct merged count of comments is displayed, but still comments of foreign language posts would be filtered out):

    function polylang_remove_comments_filter() {
        global $wp_filter;
        global $polylang;
        remove_filter('comments_clauses', array(&$polylang, 'comments_clauses'));

    Hi Mattanius,

    I tried your instructions, which worked perfectly for the default twenty-thirteen theme, but it didn’t work for Woothemes Canvas 4.7.5

    I guess woo/Canvas may have their own comments variables? Any ideas about how to adapt your code to Canvas?


    Ok – I’ve tried again, and found that the majority of the comment merging functions work.

    What doesn’t seem to work (and what was throwing me off before) is that here for example: comment counts show as 0 (ie. there are no comments yet on the English versions of the posts).

    Here, the comments are counting the Swedish versions as normal:

    However when I go into a post – regardless of whether I go in to the English or Swedish version, all comments are counted and shown correctly merged from both languages. eg:
    (Swedish version)
    (English version).

    The mods I made according to your code above also made the “recent comments” widget display no data, so I removed it. No great loss though, but maybe there is a connection?

    Little more info: It seems that it is only on (default language = swedish) and that the comment counts are not being merged.

    Also, here of course:
    and here:
    and search results.

    Merge counts for archives, categories, are working. eg:

    Any ideas here?

    Hello jongorrie, I just confirmed that comment counts on overview pages are correct with the TwentyTwelve theme (which I use), and they are, for all language versions.

    So the problem seems to be specific to your theme: I suppose that the rendering of comment counts is customized in your theme for overview pages, and you would have to detect what code (in functions.php maybe?) in that theme is responsible for it. I’m sorry – can’t give you a direct hint or I would have to dive into debugging the theme myself.

    Thanks for the quick reply!
    Here is part of my functions.php.

    $includes = array(
    				'includes/theme-options.php', 			// Options panel settings and custom settings
    				'includes/theme-functions.php', 		// Custom theme functions
    				'includes/theme-actions.php', 			// Theme actions & user defined hooks
    				'includes/theme-comments.php', 			// Custom comments/pingback loop
    				'includes/theme-js.php', 				// Load JavaScript via wp_enqueue_script
    				'includes/sidebar-init.php', 			// Initialize widgetized areas
    				'includes/theme-widgets.php',			// Theme widgets
    				'includes/theme-advanced.php',			// Advanced Theme Functions
    				'includes/theme-shortcodes.php',	 	// Custom theme shortcodes
    				'includes/woo-layout/woo-layout.php',	// Layout Manager
    				'includes/woo-meta/woo-meta.php',		// Meta Manager
    				'includes/woo-hooks/woo-hooks.php'		// Hook Manager


    And my comments.php, called above:

    // Fist full of comments
    if (!function_exists("custom_comment")) {
    	function custom_comment( $comment, $args, $depth ) {
    	   $GLOBALS['comment'] = $comment; ?>
    		<li <?php comment_class(); ?>>
    	    	<a name="comment-<?php comment_ID() ?>"></a>
    	      	<div id="li-comment-<?php comment_ID() ?>" class="comment-container">
    				<?php if( get_comment_type() == 'comment' ) { ?>
    	                <div class="avatar"><?php the_commenter_avatar( $args ); ?></div>
    	            <?php } ?>            
    		      	<div class="comment-head">
    	                <span class="name"><?php comment_author_link(); ?></span>
    	                <span class="date"><?php echo get_comment_date(get_option( 'date_format' )) ?> <?php _e('at', 'woothemes'); ?> <?php echo get_comment_time(get_option( 'time_format' )); ?></span>
    	                <span class="perma"><a href="<?php echo get_comment_link(); ?>" title="<?php _e('Direct link to this comment', 'woothemes'); ?>">#</a></span>
    	                <span class="edit"><?php edit_comment_link(__('Edit', 'woothemes'), '', ''); ?></span>
    				</div><!-- /.comment-head -->
    		   		<div class="comment-entry"  id="comment-<?php comment_ID(); ?>">
    				<?php comment_text() ?>
    				<?php if ($comment->comment_approved == '0') { ?>
    	                <p class='unapproved'><?php _e('Your comment is awaiting moderation.', 'woothemes'); ?></p>
    	            <?php } ?>
    	                <div class="reply">
    	                    <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
    	                </div><!-- /.reply -->                       
    				</div><!-- /comment-entry -->
    			</div><!-- /.comment-container -->
    if ( ! function_exists( 'list_pings' ) ) {
    	function list_pings( $comment, $args, $depth ) {
    		$GLOBALS['comment'] = $comment;
    		<li id="comment-<?php comment_ID(); ?>">
    			<span class="author"><?php comment_author_link(); ?></span> -
    			<span class="date"><?php echo get_comment_date( get_option( 'date_format' ) ); ?></span>
    			<span class="pingcontent"><?php comment_text(); ?></span>
    if ( ! function_exists( 'the_commenter_avatar' ) ) {
    	function the_commenter_avatar( $args ) {
    		global $comment;
    	    $avatar = get_avatar( $comment,  $args['avatar_size'] );
    	    echo $avatar;


    There are also other references to comments, including this one in theme-actions.php

    if ( ! function_exists( 'woo_post_more' ) ) {
    function woo_post_more() {
    	if ( get_option( 'woo_disable_post_more' ) != 'true' ) {
    	$html = '';
    	if ( get_option('woo_post_content') == 'excerpt' ) { $html .= '[view_full_article] '; }
    	$html .= '[post_comments]';
    	$html = apply_filters( 'woo_post_more', $html );
    		if ( $html != '' ) {
    	<div class="post-more">
    			echo $html;


    And this in theme-shortcodes.php

     * 8. Post Comments
     * This function produces the comment link, or a message if comments are closed.
     * @example <code>[post_comments]</code> is the default usage
     * @example <code>[post_comments zero="No Comments" one="1 Comment" more="% Comments"]</code>
    if ( ! function_exists( 'woo_shortcode_post_comments' ) ) {
    function woo_shortcode_post_comments ( $atts ) {
    	global $post;
    	$defaults = array(
    		'zero' => '<i class="icon-comment"></i> 0',
    		'one' => '<i class="icon-comment"></i> 1',
    		'more' => '<i class="icon-comment"></i> %',
    		'hide_if_off' => 'enabled',
    		'closed_text' => apply_filters( 'woo_post_more_comment_closed_text', __( 'Comments are closed', 'woothemes' ) ),
    		'before' => '',
    		'after' => ''
    	$atts = shortcode_atts( $defaults, $atts );
    	$atts = array_map( 'wp_kses_post', $atts );
    	if ( ( ! get_option( 'woo_comments' ) || ! comments_open() ) && $atts['hide_if_off'] === 'enabled' )
    	if ( $post->comment_status == 'open' ) {
    		// Darn you, WordPress!
    		comments_number( $atts['zero'], $atts['one'], $atts['more'] );
    		$comments = ob_get_clean();
    		$comments = sprintf( '<a href="%s">%s</a>', get_comments_link(), $comments );
    	} else {
    		$comments = $atts['closed_text'];
    	$output = sprintf('<span class="post-comments comments">%2$s%1$s%3$s</span>', $comments, $atts['before'], $atts['after']);
    	return apply_filters( 'woo_shortcode_post_comments', $output, $atts );
    } // End woo_shortcode_post_comments()
    add_shortcode( 'post_comments', 'woo_shortcode_post_comments' );


    I’m not a programmer (as you can probably tell!) but am trying to use a process of deduction to find out what’s going on here.

    Can you make sense of the above?

    I have created a test site at

    If you have the time, perhaps I could give you an admin login to check out the code?


    Changed: $languages = icl_get_languages(‘skip_missing=1’);
    To: $languages = icl_get_languages();


Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Multilang comment’ is closed to new replies.