WP_Comment_Query – Get comments and answers separately


I was developing a theme and this time I chose to use the bootstrap4, I found some difficulties in the way but I managed to solve them and the result was satisfactory, however creating my comments.php I noticed that wordpress does not differentiate comments from answers, for example:

So how do I get the comments and answers separately? I would like to pick up the answers separately to be able to add further below your respective comments.


<!--    Comentarios    -->
<asside class="comments-area container">
    <?php if(have_comments()) : ?>
    <div class="col-md-10 offset-md-1">
        <h3 class="mb-4">Comentários</h3>
            $comment_args = array(
                'order'    =>    'DEC'
            $comment_query = new WP_Comment_Query;
            $comment = $comment_query->query($comment_args);
            foreach($comment as $comment) :
        <!--    comentario    -->
        <div class="blog-comment row mb-2">
            <div class="comment-avatar col-md-1 pr-1">
                <img class="mx-auto rounded-circle img-fluid" src="<?php echo get_avatar_url($comment->comment_author_email ); ?>" alt="avatar"/>
            <div class="comment-content col-md-11">
                <h6 class="comment-meta small">Por <?php echo $comment->comment_author; ?> em <?php echo comment_date('d-m-Y'); ?></h6>
                <div class="comment-body">
                        <?php echo $comment->comment_content; ?>
        <?php endforeach; ?>
    <?php endif; ?>

Read more here:: WP_Comment_Query – Get comments and answers separately

Leave a Reply

Your email address will not be published. Required fields are marked *