count_many_users_posts()
count_many_users_posts( int[] $users, string|string[] $…
count_many_users_posts( int[] $users, string|string[] $post_type = ‘post’, bool $public_only = false )
由用户列表撰写的文章数。
Number of posts written by a list of users.
目录锚点:#参数#返回#源码#笔记
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| $users | (int[]) | 必需 | 用户ID数组。 | 
| $post_type | (string | string[]) | 可选 | 要检查的单个日志类型或日志类型数组。默认为“发布”。 | 
| $public_only | (bool) | 可选 | 只有公共职位才算回报。默认为false。 | 
返回(Return)
(string[])每个用户以string形式按用户ID键入的文章数量。
源码(Source)
/**
 * 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
//| 更新版本 | 源码位置 | 使用 | 被使用 | 
|---|---|---|---|
| 3.0.0 | wp-includes/user.php:404 | 1 function | 2 | 
笔记(Notes)
返回用户id列表的post计数。
类别:WordPress 函数手册、 
		本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!