• I made a plugin, which should show latest comments with excerpt. it contain this code

    echo "<a href='" . get_permalink($comment->comment_post_ID) .
    '#comment-' . $comment->comment_ID . "'>" .
    $comment->comment_excerpt . "</a>";

    The problem is that returned code does not contain the excerpt. There is comment_post_ID, there is comment_ID, i then return also comment->comment_author and comment->comment_author_url without problems, but the comment_excerpt easily just not work. Is it bug or do i do it wrong? The function seems to exist (https://codex.www.ads-software.com/Template_Tags/comment_excerpt)

    is there any way how I can get latest xxx chars rounded to words from the comment?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Comments do not have an excerpt record; comment_excerpt() just extracts the ‘excerpt’ from a comment’s content.

    You can try using get_comment_excerpt() in your plugin, or look that function over in the source and copy over the relevant features.

    Thread Starter thomask

    (@thomask)

    why the documentation says, it will return 20 words – is it bug in documentation?

    I do not understand the rest – please can you help me with exact code, what should i use?
    This is my 0.1 plugin


    function excerpt_comments($number='5', $before='<li>', $middle=' <small>(', $after=')</small></li>') {
    global $wpdb;
    $sql = "SELECT comment_author, comment_author_url, comment_ID, " .
    "comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' " .
    "ORDER BY comment_date_gmt DESC LIMIT $number";
    if ( $comments = $wpdb->get_results($sql) ) {
    foreach ($comments as $comment) {
    echo "$before";
    echo "<a href='" . get_permalink($comment->comment_post_ID) .
    '#comment-' . $comment->comment_ID . "'>" .
    $comment->comment_excerpt . "</a>";
    echo "$middle";
    if($comment->comment_author_url) {
    echo '<a href="' .$comment->comment_author_url. '" rel="nofollow">';
    }
    echo "$comment->comment_author";
    if($comment->comment_author_url) {
    echo '</a>';
    }
    echo "$aftern";
    }
    }
    }
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘comment_excerpt does not work – bug or mistake?’ is closed to new replies.