Reputation: 1724
I have a page to display all the users. The users type are author. To display the all the agent.
$args = array(
'role' => 's2member_level2',
'meta_query' => array(
array(
'key' => $filter,
'value' => $_GET['filter'],
'compare' => 'LIKE'
)
)
);
}
$users = get_users($args);
if ($users) {
foreach ($users as $user) {
$user_profile_data = get_user_meta($user->ID,'wp_s2member_custom_fields',true);
//print_r($user_profile_data);
echo '<div class="user_data" >';
echo '<a href="'.site_url().'/author/'.$user->user_login.'">'.user_avatar_get_avatar($user_info->ID,'110').'</a>';
echo '<div class="user-info">';
//print_r($users);
echo '<h6>'.'<a href="'.site_url().'/author/'.$user->user_login.'">'.$user->display_name.'</a></h6>';
if ($user_profile_data[contact_number])
echo '<p> call-'.$user_profile_data[contact_number].'</p>';
else
echo '<p> Phone number not specified.</p>';
echo '<p>'.$user->user_email.'</p>';
echo '</div>';
echo '<div class="agent_specify" >';
$agent_specify = $user_profile_data[posting_preferance];
echo '<p>Agent Speciality :</p>';
if ($agent_specify) {
echo '<ul>';
foreach ($agent_specify as $specification){
echo '<li>'.$specification.'</li>';
}
echo '</ul>';
}
else {
echo '<p style="font-weight: normal;">Not specified</p>';
}
echo '</div>';
echo '<a href="'.site_url().'/author/'.$user->user_login.'/#contact">contact »</a>';
echo '</div>';
}
}
else {
echo '<h4>No agents found.</h4>';
}
?>
</div>
I can find the user list, but i want to pagination here, because i have lot of users here in the page.
Upvotes: 0
Views: 2461
Reputation: 1073
ok you can use WP_User_Query() function for this juss check out and i did alittle bit of work for you.
$no=5;// total no of author to display
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if($paged==1){
$offset=0;
}
else {
$offset= ($paged-1)*$no;
}
$args = array(
'role' => 's2member_level2',
'number' => $no, 'offset' => $offset,
'meta_query' => array(
array(
'key' => $filter,
'value' => $_GET['filter'],
'compare' => 'LIKE'
)
));
$user_query = new WP_User_Query( $args );
if ( !empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
..... ur code goes here
}
}
else {
echo '<h4>No agents found.</h4>';
}
And for pagination it depends oon how your structure is if its permalink is post name then you can use pagination code as
$total_user = $user_query->total_users;
$total_pages=ceil($total_user/$no);
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '?paged=%#%',
'current' => $paged,
'total' => $total_pages,
'prev_text' => 'Previous',
'next_text' => 'Next'
));
hope this will work for you :)
Upvotes: 5