I have this code that get me last comments in my site :

function bg_recent_comments($no_comments = 30, $comment_len = 80, $avatar_size = 48) {
                        $comments_query = new WP_Comment_Query();
                        $comments = $comments_query->query( array( 'number' => $no_comments , 'status' => 'approve') );
                        $comm = '';
                        if ( $comments ) : foreach ( $comments as $comment ) :
                            $comm .= '<li id="comment-160546">
                            <br><a href="'.get_permalink($comment->comment_post_ID).'" style="font-family:droid arabic kufi;text-align: center;font-style: italic;font-weight: bold;font-size: 15px;">'.get_the_title($comment->comment_post_ID).'</a><br><br>
                                <div class="comment byuser comment-author-hasan-ly odd alt thread-odd thread-alt depth-1 comment-wrap">
                                    <div class="comment-avatar">'.get_avatar( $comment->comment_author_email, $avatar_size ).'</div>
                                    <div class="comment-content">
                                        <div class="author-comment">
                                            <cite class="fn">'.get_comment_author( $comment->comment_ID ).'</cite>                  
                                            <div class="comment-meta commentmetadata"><a href="' . get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID . '">Post URL</a></div><!-- .comment-meta .commentmetadata -->
                                            <div class="clear"></div>
                                        <p>' . $comment->comment_content . '</p>
                                </div><!-- #comment-##  --><br>
                        endforeach; else :
                            $comm .= 'No comments.';
                        echo $comm; 

Now my problem is when add comment_reply_link to can any user replay to this comment. its now show the form reply,

When var_dump comment_reply_link its return me NULL.

How can solve it


The function comment_reply_link echos the function get_comment_reply_link. If you look at the source code you see, that up to 3 arguments are needed for a proper functionality.

  1. $args an array of optional arguments that overwrite the default values
  2. $comment an optional comment_id or WP_Comment object the comment should reply to.
  3. $post an optional post_id or WP_Post object where the comment is going to be displayed on.

If the function returns null, it cannot figure out the relating $post. Try to add this parameter to your function call, e.g. comment_reply_link(null, null, $post_id) or $comm.= get_comment_reply_link(null, $comment); (within your foreach loop).

If the function returns false, comments are disabled for this post.

Source: developer.wordpress.org

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.