0

I want to retrieve the comments of the current post in the comments.php file. I have this:

<?php 

if (comments_open()) {

    $args = array(
        'post_id' => "|what to put here ?|",
        'order'   => 'ASC'
    );
    $comments = get_comments($args);
    ?>
    <div class="comments-area">
        <h4><?php comments_number('0 Comments', '1 Comments', '% Comments'); ?> post id is <?php echo "$postid"; ?></h4>
        <?php foreach ($comments as $comment): ?>
        <ul class="comment-list">
            <li class="single-comment justify-content-between d-flex">
                <div class="user justify-content-between d-flex">
                    <div class="thumb">
                        <?php echo get_avatar( $comment->comment_author_email, 32 ); ?>
                    </div>
                    <div class="desc">
                        <h5><?php echo "$comment->comment_author"; ?></h5>
                        <p class="date"><?php echo "$comment->comment_date"; ?></p>
                        <p class="comment">
                            <?php echo "$comment->comment_content"; ?>
                        </p>
                    </div>
                </div>
                <div class="reply-btn">
                       <a href="" class="btn-reply text-uppercase">reply</a> 
                </div>
            </li>
        </ul>
        <?php endforeach ?>
    </div>

    <?php comment_form();
}else{
    echo "comments disabled";
}

When I put nothing in line 4: 'post_id' => "", I get all the comments in the blog. How to get only the comments of that post? I need to dynamically get the post id!

enter image description here

  • 1
    cause i dont want the regular HTML that wp_list_comments() provides i want my own HTML that i have olready writen – bilal BOUASRIA Aug 29 '19 at 21:03
0

You should be able to start your function with global $post;. Then, your $args would look like this:

$args = array(
        'post_id' => $post->ID,
        'order'   => 'ASC'
    );
  • thank you very very much i got what i want, thanks to you. – bilal BOUASRIA Aug 29 '19 at 21:06

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.