count_many_users_posts
函数
count_many_users_posts ( $users, $post_type = 'post', $public_only = false )
- 参数
-
-
(int[])
$users
Array of user IDs.- Required: 是
-
(string|string[])
$post_type
Optional. Single post type or array of post types to check. Defaults to ‘post’.- Required: 否
- Default: ‘post’
-
(bool)
$public_only
Optional. Only return counts for public posts. Defaults to false.- Required: 否
- Default: false
-
(int[])
- 返回值
-
- (string[]) Amount of posts each user has written, as strings, keyed by user ID.
- 定义位置
-
-
wp-includes/user.php
, line 588
-
wp-includes/user.php
- 引入
- 3.0.0
- 弃用
- –
Gets the number of posts written by a list of users.
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; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。