Paginate result set from $wpdb->get_results()

You can use the function paginate_links() for any pagination.

For your specific case:

$total = $wpdb->get_var("
    SELECT COUNT(comment_ID)
    FROM $wpdb->comments
    WHERE user_id = $thisauthor->ID
    AND comment_post_id = ID
    AND comment_approved = 1
");
$comments_per_page = 100;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;

echo paginate_links( array(
    'base' => add_query_arg( 'cpage', '%#%' ),
    'format' => '',
    'prev_text' => __('«'),
    'next_text' => __('»'),
    'total' => ceil($total / $comments_per_page),
    'current' => $page
));

Leave a Comment