Advertisements

count_many_users_posts

Definition:
function count_many_users_posts($users, $post_type = 'post' ) {}

Number of posts written by a list of users.

Parameters

  • array $user_ids: Array of user IDs.
  • string|array $post_type: Optional. Post type to check. Defaults to post.
  • $users

Return values

returns:Amount of posts each user has written.

Source code

function count_many_users_posts($users, $post_type = 'post' ) {

	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 );



	$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;

}

734

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: