Here we will learn about User pagination function in WordPress with get_users function. We have used user-role “member” for this example, you have to user your own created user role.

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

$args = array(
    'role' => 'member',
    'orderby' => 'registered',
    'order' => 'ASC',
);
$users = get_users($args);

$args = array(
    'role' => 'member',
    'orderby' => 'registered',
    'order' => 'ASC',
    'number' => $number,
    'offset' => $offset
);
$meber_arr = get_users($args);

$total_users = count($users);
$total_query = count($meber_arr);
$total_pages = ceil($total_users / $number);

foreach ($meber_arr as $userdata) {
    print_r(userdata)
}
$big = 999999999; // need an unlikely integer
$mypagei = paginate_links(array(
    'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
    'format' => '&p=%#%',
    'prev_text' => __('&laquo; Previous'),
    'next_text' => __('Next &raquo;'),
    'total' => $total_pages,
    'current' => $paged,
    'end_size' => 1,
    'mid_size' => 5,
));

if ($mypagei != '') {
echo $mypagei; 
}
There are currently no comments.