• I setup a widget that displays recent comments on my website using the code below. However, that code also displays trackbacks, which I don’t want.

    Is there anyway to modify the code below to not display trackbacks, only legitimate comments? Thanks.

    <?php
    $query = "SELECT * from $wpdb->comments WHERE comment_approved= '1'
    ORDER BY comment_date DESC LIMIT 0 ,5";
    $comments = $wpdb->get_results($query);
    
    if ($comments) {
    echo '<ul style="list-style-type:none">';
    foreach ($comments as $comment) {
    $url = '<a href="'. get_permalink($comment->comment_post_ID).'#comment-'.$comment->comment_ID .'" title="'.$comment->comment_author .' | '.get_the_title($comment->comment_post_ID).'">';
    echo '<li style="min-height:40px;border-bottom: 1px dotted #AAA;
    margin-bottom: 10px;
    padding-bottom: 5px;">';
    echo '<div style="float:left" class="img">';
    echo $url;
    echo get_avatar( $comment->comment_author_email, 32);
    echo '</a></div>';
    echo $comment->comment_author . " said: ";
    echo comment_excerpt();
    echo '</li>';
    }
    echo '</ul>';
    }
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • mandrill

    (@mandrill)

    I too would like to stop the recent comments widget from displaying trackbacks and pings.

    Khang Minh

    (@oddoneout)

    Please change this:

    $query = “SELECT * from $wpdb->comments WHERE comment_approved= ‘1’
    ORDER BY comment_date DESC LIMIT 0 ,5″;

    to this:

    $query = “SELECT * FROM $wpdb->comments WHERE comment_approved = 1 AND comment_type = ” ORDER BY comment_date DESC LIMIT 0, 5″;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Stop displaying trackbacks in Recent Comments widget’ is closed to new replies.