count_many_users_posts( array $users, string|array $post_type = 'post', bool $public_only = false )
Number of posts written by a list of users.
描述
参数
- $users
-
(array)
(Required)
Array of user IDs. - $post_type
-
(string|array)
(Optional)
Single post type or array of post types to check. Defaults to ‘post’.Default value: ‘post’
- $public_only
-
(bool)
(Optional)
Only return counts for public posts. Defaults to false.Default value: false
返回值
(array) Amount of posts each user has written.
源代码
File: wp-includes/user.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;
}
更新日志
Version | 描述 |
---|---|
3.0.0 | Introduced. |
相关函数
Uses
-
wp-includes/post.php:
get_posts_by_author_sql() -
wp-includes/wp-db.php:
wpdb::get_results()
Used By
-
wp-admin/includes/class-wp-users-list-table.php:
WP_Users_List_Table::display_rows()
User Contributed Notes
-
Skip to note content
You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note
Contributed by
Codex
Returns the post counts for a list of user IDs.
$users = array( 1, 3, 9, 10 ); $counts = count_many_users_posts( $users ); echo 'Posts made by user 3: ' . $counts[3];
Output:
Posts made by user 3: 143
你可能对这些文章感兴趣:
- wordpress函数gd_edit_image_support()用法示例
- wordpress函数gallery_shortcode()用法示例
- wordpress函数funky_javascript_callback()用法示例
- wordpress函数funky_javascript_fix()用法示例
- wordpress函数format_to_edit()用法示例
- wordpress函数format_to_post()用法示例
- wordpress函数form_option()用法示例
- wordpress函数force_ssl_login()用法示例
- wordpress函数format_code_lang()用法示例
- wordpress函数format_for_editor()用法示例
- wordpress函数force_ssl_content()用法示例
- wordpress函数flush_rewrite_rules()用法示例
- wordpress函数force_balance_tags()用法示例
- wordpress函数force_ssl_admin()用法示例
如有疑问,请前往问答中心反馈!
反馈