如何对 get_users 函数进行分页?
我使用 get_users 函数来显示网站上的自定义用户列表。我现在遇到的唯一问题是如何对结果进行分页。
这是我使用的函数的示例:
<ul>
<?php
$args = array(
'meta_key' => 'jabber',
'meta_value' => 'User Name',
'meta_compare' => 'LIKE',
'order' => 'ASC',
'count_total' => true,
'fields' => 'all',
);
$blogusers = get_users($args_1);
foreach ($blogusers as $user) {
$user_id = $user->ID;
$user = get_userdata($user_id);
echo '<li class="provider-list prov-list-gradient">' . $user->display_name . '</li>';
}
?>
</ul>
似乎没有一种明显的方法来为此函数创建分页。我希望得到一些帮助。
更新:
这是 get_users 函数源代码:
function get_users( $args = array() ) {
$args = wp_parse_args( $args );
$args['count_total'] = false;
$user_search = new WP_User_Query($args);
return (array) $user_search->get_results();
}
Im using the get_users function to show a custom list of users on the site. The only issue Im having a problem figuring out now is how to paginate the result.
This is a sample of the function that Im using:
<ul>
<?php
$args = array(
'meta_key' => 'jabber',
'meta_value' => 'User Name',
'meta_compare' => 'LIKE',
'order' => 'ASC',
'count_total' => true,
'fields' => 'all',
);
$blogusers = get_users($args_1);
foreach ($blogusers as $user) {
$user_id = $user->ID;
$user = get_userdata($user_id);
echo '<li class="provider-list prov-list-gradient">' . $user->display_name . '</li>';
}
?>
</ul>
There doesn't seem to be an obvious way of creating a pagination for the this function. I would appreciate some help with this.
UPDATE:
This is the get_users function source code:
function get_users( $args = array() ) {
$args = wp_parse_args( $args );
$args['count_total'] = false;
$user_search = new WP_User_Query($args);
return (array) $user_search->get_results();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在加载每页
N
结果之前运行get_users()
,则可以修改get_users()
查询以使用 < mysql 中的 code>OFFSET 关键字。伪查询示例(其中
P
是您的页码):Provided you're running
get_users()
before you load each page ofN
results, you could revise yourget_users()
query to use theOFFSET
keyword in mysql.Pseudoquery example (where
P
is your page number):