用户列表写的帖子数。
原型
count_many_users_posts( array $users, string|array $post_type = 'post', bool $public_only = false )
参数
$users
(array)
(Required)
用户ID数组。
$post_type
(string|array)
(Optional)
单一帖子类型或要检查的帖子类型数组。默认为“发布”。
$public_only
(bool)
(Optional)
仅返回公共职位的计数。默认为false。
返回值
(array)
每个用户撰写的帖子数量。
源文件
路径:wp-includes/user.php
<?php
...
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;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/count_many_users_posts/