Make WordPress Core

Ticket #21364: get-user-post-count-post-type.21364.diff

File get-user-post-count-post-type.21364.diff, 2.0 KB (added by engelen, 10 years ago)
  • src/wp-includes/author-template.php

    diff --git src/wp-includes/author-template.php src/wp-includes/author-template.php
    index 5ad7059..d8df93c 100644
    function the_author_link() { 
    203203 *
    204204 * @uses $post The current post in the Loop's DB object.
    205205 * @uses count_user_posts()
    206  * @return int The number of posts by the author.
     206 * @param string $post_type Optional. Post type to count the number of posts for. Defaults to "post".
     207 * @return int The number of posts in the post type by the author.
    207208 */
    208 function get_the_author_posts() {
     209function get_the_author_posts( $post_type = 'post' ) {
    209210        $post = get_post();
    210211        if ( ! $post ) {
    211212                return 0;
    212213        }
    213         return count_user_posts( $post->post_author );
     214        return count_user_posts( $post->post_author, $post_type );
    214215}
    215216
    216217/**
  • src/wp-includes/user.php

    diff --git src/wp-includes/user.php src/wp-includes/user.php
    index a548f5a..efb4da1 100644
    function wp_validate_logged_in_cookie( $user_id ) { 
    254254 * @global wpdb $wpdb WordPress database object for queries.
    255255 *
    256256 * @param int $userid User ID.
    257  * @return int Amount of posts user has written.
     257 * @param string $post_type Optional. Post type to count the number of posts for. Defaults to "post".
     258 * @return int Number of posts the user has written in this post type.
    258259 */
    259 function count_user_posts($userid) {
     260function count_user_posts( $userid, $post_type = 'post' ) {
    260261        global $wpdb;
    261262
    262         $where = get_posts_by_author_sql('post', true, $userid);
     263        $where = get_posts_by_author_sql( $post_type, true, $userid );
    263264
    264265        $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    265266
    function count_user_posts($userid) { 
    270271         *
    271272         * @param int $count  The user's post count.
    272273         * @param int $userid User ID.
     274         * @param string $post_type Post type to count the number of posts for.
    273275         */
    274         return apply_filters( 'get_usernumposts', $count, $userid );
     276        return apply_filters( 'get_usernumposts', $count, $userid, $post_type );
    275277}
    276278
    277279/**