WordPress函数文档count_many_users_posts()
返回多个用户的文章总数 描述 Returns the post counts for a list of us…
返回多个用户的文章总数
描述
Returns the post counts for a list of user IDs. This is an O(n) operation, so it is preferred over count_user_posts() any time more than a single count is needed.
用法
<?php count_many_users_posts( $users, $post_type, $public_only ); ?>
参数
$users
(array) (必填) List of ID values of the users whose post counts should be retrieved.
默认值: None
$post_type
(string) (可选) Name of the post type
默认值: null
$public_only
(string) (可选) Bypasses checking capabilities of current user (False) or returns posts only if they can be viewed by current user (True).
默认值: False
历史
- 3.5.0: 添加 public_only parameter
- 添加于 版本: 3.0.0
源文件
count_many_users_posts() 函数的代码位于 wp-includes/user.php
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* Number of posts written by a list of users.
*
* @since 3.0.0
*
* @global wpdb $wpdb
*
* @param array $users Array of user IDs.
* @param string|array $post_type Optional. Single post type or array of post types to check. Defaults to ‘post’.
* @param bool $public_only Optional. Only return counts for public posts. Defaults to false.
* @return array Amount of posts each user has written.
*/
function count_many_users_posts( $users, $post_type = ‘post’, $public_only = false ) {
global $wpdb;
$count = array();
if ( empty( $users ) || ! is_array( $users ) )
return $count;
$userlist = implode( ‘,’, array_map( ‘absint’, $users ) );
$where = get_posts_by_author_sql( $post_type, true, null, $public_only );
$result = $wpdb->get_results( “SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author”, ARRAY_N );
foreach ( $result as $row ) {
$count[ $row[0] ] = $row[1];
}
foreach ( $users as $id ) {
if ( ! isset( $count[ $id ] ) )
$count[ $id ] = 0;
}
return $count;
}
//
// User option functions
//
|
相关
count_user_posts,
get_posts_by_author_sql
- 原文:http://codex.wordpress.org/Function_Reference/count_many_users_posts
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!