0

I have small problem, I have author page (example.com/author/joe) on this page I have listed all author comments with pagination but pagination doesn't work after click url is - example.com/author/joe/page/2 and page is redirect to index.php.

In other loops it works, just have problem with author page.

Any ideas ?

CODE:

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$number = get_option('comments_per_page');
$offset = ( $paged - 1 ) * $number;

$count = count( get_comments( array(
    'user_id' => $user_ID,
    'status' => 'approve',
) ) );

$max_total = ceil($count/$number);

$args = array(
    'user_id' => $user_ID,
    'number' => $number,
    'status' => 'approve',
    'offset' => $offset,
    'paged' => $paged
    );

$the_query = new WP_Comment_Query;
$comments = $the_query->query( $args );

foreach($comments as $comment){ 
 //code
}


//Pagination
$big = 999999999;

echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $max_total,
    'prev_next'=> true,
) ); 
3
  • 1
    Post code of yours.
    – bravokeyl
    Oct 5, 2016 at 7:06
  • Code added. Matt Oct 5, 2016 at 7:50
  • Any ideas, what can be wrong ? Oct 6, 2016 at 11:31

1 Answer 1

0

Make sure you've set the paged parameter in your query, below is shown how to do that.

<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
     'posts_per_page' => 3,
     'paged' => $paged
); 
$the_query = new WP_Query( $args ); 
?>

For more information about pagination have a look at this page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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