wpseek.com
A WordPress-centric search engine for devs and theme authors
count_user_posts › WordPress Function
Since3.0.0
Deprecatedn/a
› count_user_posts ( $userid, $post_type = 'post', $public_only = false )
Parameters: (3) |
|
Returns: |
|
Defined at: |
|
Codex: | |
Change Log: |
|
Gets the number of posts a user has written.
Related Functions: count_many_users_posts, count_users, wp_count_posts, get_usernumposts, query_posts
Source
function count_user_posts( $userid, $post_type = 'post', $public_only = false ) { global $wpdb; $post_type = array_unique( (array) $post_type ); sort( $post_type ); $where = get_posts_by_author_sql( $post_type, true, $userid, $public_only ); $query = "SELECT COUNT(*) FROM $wpdb->posts $where"; $last_changed = wp_cache_get_last_changed( 'posts' ); $cache_key = 'count_user_posts:' . md5( $query ) . ':' . $last_changed; $count = wp_cache_get( $cache_key, 'post-queries' ); if ( false === $count ) { $count = $wpdb->get_var( $query ); wp_cache_set( $cache_key, $count, 'post-queries' ); } /** * Filters the number of posts a user has written. * * @since 2.7.0 * @since 4.1.0 Added `$post_type` argument. * @since 4.3.1 Added `$public_only` argument. * * @param int $count The user's post count. * @param int $userid User ID. * @param string|array $post_type Single post type or array of post types to count the number of posts for. * @param bool $public_only Whether to limit counted posts to public posts. */ return apply_filters( 'get_usernumposts', $count, $userid, $post_type, $public_only ); }