Не работает пагинация комментариев wordpress
Всем привет. Есть пагинация комментариев. При переходе например на страницу пагинации (/page/2) - идет загрузка и открывается эта же страница где мы были только что. И если даже комментариев нету, то пагинация всё равно выводится. Код:
<?php
$comments_per_page = 5;
$page = (!get_query_var('paged')) ? 1 : get_query_var('paged');
$comments = get_comments(array(
'post_id' => $product->ID,
'post_parent' => $post->ID,
'status' => 'approve',
'number' => $comments_per_page,
));
foreach( $comments as $comment ){ ?>
<div class="tab-review-item">
<div class="tab-review-image"></div>
<div class="tab-review-content">
<div class="tab-review-top">
<?php $rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) ); if ( $rating && wc_review_ratings_enabled() ) {
echo wc_get_rating_html( $rating ); // WPCS: XSS ok.
} ?>
<div class="tab-review-user-info">
<div class="tab-review-name">отзыв от клиента <strong><?php echo $comment->comment_author; ?></strong></div>
<div class="tab-review-product-title">
на товар: <strong><a href="<?php echo get_comment_link(); ?>"><?php echo $comment->post_title; ?></a></strong></div>
</div>
</div>
<div class="tab-review-comment"><?php echo $comment->comment_content;?></div>
</div>
</div>
<?php }
$total_comments = get_comments(
array_merge($comments,
array(
'count' => true,
'offset' => 0,
'number' => 0
)
)
);
?>
<div class="navigation">
<?php
$args = array(
'total' => ceil( $total_comments / $comments_per_page ),
'current' => max( 1, $page ),
'show_all' => false,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => True,
'prev_text' => __('« Previous'),
'next_text' => __('Next »'),
'type' => 'plain'
);
echo paginate_links( $args );
?>