The MU forums have moved to WordPress.org

Feed error after deleting posts (2 posts)

  1. Konstan
    Member
    Posted 19 years ago #

    Ok, so here is an error I am getting:

    [18-Aug-2007 19:34:10] WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 10' at line 1]
    SELECT wp_332_comments.* FROM wp_332_comments  WHERE comment_post_ID =  AND comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 10

    I checked the latest visitors and found out that this error was caused when someone tried to access the feed for a post that has been deleted via google.

    Now, its not a biggie, but it still bothers me because my error_log gets full of these. Is this a software bug or do I have something configured wrong?

    The error only appears when someone tries to view the feed for a post that doesnt exist. You can access the feed, but it wont show you anything. If I delete the /feed/ from the url I get a 404 message. The /feed/ doesnt show me the mysql error, it just loads the typicall feed page but blank.

    Anyway to fix this?

  2. webmaestro
    Member
    Posted 18 years ago #

    I'm seeing similar errors, and unfortunately you don't have any responses to your forum post...

    It looks like this is a result from the query in this file:

    wordpress-mu-1.3.3/wp-includes/query.php
    
            if ( $this->is_comment_feed && $this->is_singular ) {
                $cjoin = apply_filters('comment_feed_join', '');
                $cwhere = apply_filters('comment_feed_where', "WHERE comment_post_ID = {$this->posts[0]->ID} AND comment_approved = '1'");
                $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss');
                $this->comments = $wpdb->get_results($comments_request);
                $this->comment_count = count($this->comments);
            }

    The 'meat' of the code is here:

    SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss');

    For some reason, on this instance '$cwhere' isn't resolving this portion:

    {$this->posts[0]->ID}

    I suspect someone (a spammer?) is trying to comment on a post that's been deleted.

    Perhaps a 'fix' could be to check to see if the post exists before doing the select for the feed, via something like this:

    if ( $this->is_comment_feed && $this->is_singular ) {
    $cjoin = apply_filters('comment_feed_join', '');
    $cwhere = apply_filters('comment_feed_where', "WHERE comment_post_ID = {$this->posts[0]->ID} AND comment_approved = '1'");
    if ({$this->posts[0]->ID})
    $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss');
    $this->comments = $wpdb->get_results($comments_request);
    $this->comment_count = count($this->comments);
    }`

    I added ' if ({$this->posts[0]->ID})'

    I don't know if it'll work, though...

About this Topic

  • Started 19 years ago by Konstan
  • Latest reply from webmaestro