Skip to content

Recent Comments Widget only shows comments when logged in #38

@GoogleCodeExporter

Description

@GoogleCodeExporter
What steps will reproduce the problem?
1. Go to Wordpress Backend -> Apperance -> Widgets.
2. Drag Recent Comments Widget (which is included in WP Core, but overwritten 
by WMPL) in any sidebar
3. Visit Frontend and have a look at the widget. If you are logged in in the 
backend, comments will be shown. If aren't looged in in the backend anymore, 
comments won't be shown anymore.



I have a hint where the error could be:

In file inc/icl-recent-comments-widget.php : line 19
        $comments = $wpdb->get_results("
            SELECT * FROM {$wpdb->comments} c
                JOIN {$wpdb->prefix}icl_translations t ON c.comment_post_id = t.element_id AND t.element_type='post_post'
            WHERE comment_approved = '1' AND language_code = '".$sitepress->get_current_language()."'
            ORDER BY comment_date_gmt DESC LIMIT {$number}
        ");


If you replace this with:

        $comments = $wpdb->get_results("
            SELECT * FROM {$wpdb->comments}
                JOIN {$wpdb->prefix}icl_translations ON {$wpdb->comments}.comment_post_id = {$wpdb->prefix}icl_translations.element_id AND {$wpdb->prefix}icl_translations.element_type='post_post'
            WHERE comment_approved = '1' AND language_code = '".$sitepress->get_current_language()."'
            ORDER BY comment_date_gmt DESC LIMIT {$number}
        ");

everything works again.

It seems to me as if wordpress is inserting some statements into the sql query 
when being executed. These statements don't know about the shorthands for the 
tables (c and t). If you enable WP_DEBUG, you can see error messages for that. 
But I don't know why this error affects the query when being not looged in and 
does not affect when being logged in.



What version of WPML and WordPress are you using? Can you also specify PHP
and MySQL versions?

WPML 2.0.4
PHP 5.2.14-0.dotdeb.0
MySQL 5.0.51a-24+lenny4

Original issue reported on code.google.com by zawiw.we...@uni-ulm.de on 7 Jan 2011 at 9:23

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions