count_many_users_posts()

count_many_users_posts()函数是Wordpress函数,由用户列表撰写的文章数。

count_many_users_posts( int[] $users, string|string[] $post_type = ‘post’, bool $public_only = false )

参数(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.0wp-includes/user.php:4041 function2
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索