• Resolved ben.IT

    (@benit)


    Hi,
    My current theme lists the last comments on the home page.
    I wonder how can I do to query only the comments in the page language ?

    Actually, The theme uses this query :
    $comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) );

    I would like to the same but adding the language criteria, any idea ?
    thanks,
    greetings, ben

    http://wordpress.org/extend/plugins/polylang/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ben.IT

    (@benit)

    Hi, I find a solution which works using the fine polylang API :

    //Original : does not manage language. display all comments. doesn't care about the comment language
    		//$comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) );
    		/************************************************************/
    
    		$current_lng= pll_current_language(); //retrieve current language
    		$lng_objects = get_posts(array(
    		'post_type' => 'post',
    		'lang' => $current_lng, // use language slug in the query
    		'showposts' => 150 //remove if problem. here for perf. this prevents loading all posts.
    ));
    $lng_ids=array() ;
    foreach ($lng_objects as $objects)
    	array_push($lng_ids, $objects->ID) ;
    $string_lng_ids=implode(",", $lng_ids); //build ID string for sql query
    
    global $wpdb;
    $query_lng_comments="
    select wp3_comments.*
    from wp3_comments
    inner join wp3_posts on wp3_posts.ID=wp3_comments.comment_post_ID
    where comment_approved=1
    and wp3_posts.ID in ($string_lng_ids)
    order by comment_date desc
    limit 0,$number
    ";
    $comments=$wpdb->get_results($query_lng_comments);
    /*********************************************************/

    Hope this could help.
    greetings,
    ben

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

    Plugin Author Chouby

    (@chouby)

    Thanks for sharing! However, I am surprised that it does not work for you as it currently works for the widget “recent comments” which uses the same function get_comments

    Thread Starter ben.IT

    (@benit)

    Don’t know why either. Thanks for your answer.
    Ben

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin : Polylang] – How to get the latest comments for the current language ?’ is closed to new replies.