Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

I use the following codefollowing code to count user posts by specific post type:

function count_user_posts_by_type( $userid, $post_type ) {
    global $wpdb;
    $where = get_posts_by_author_sql( $post_type, TRUE, $userid );
    $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    return apply_filters( 'get_usernumposts', $count, $userid );
}

// Echo Count
echo count_user_posts_by_type( $user_ID, 'reports' );

Looking for an elegant solution to limit posts by dates. For example, last week\month posts.

I use the following code to count user posts by specific post type:

function count_user_posts_by_type( $userid, $post_type ) {
    global $wpdb;
    $where = get_posts_by_author_sql( $post_type, TRUE, $userid );
    $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    return apply_filters( 'get_usernumposts', $count, $userid );
}

// Echo Count
echo count_user_posts_by_type( $user_ID, 'reports' );

Looking for an elegant solution to limit posts by dates. For example, last week\month posts.

I use the following code to count user posts by specific post type:

function count_user_posts_by_type( $userid, $post_type ) {
    global $wpdb;
    $where = get_posts_by_author_sql( $post_type, TRUE, $userid );
    $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    return apply_filters( 'get_usernumposts', $count, $userid );
}

// Echo Count
echo count_user_posts_by_type( $user_ID, 'reports' );

Looking for an elegant solution to limit posts by dates. For example, last week\month posts.

Tweeted twitter.com/StackWordPress/status/745421976043298816
Source Link
Rami
  • 61
  • 5

Count user posts by type and date

I use the following code to count user posts by specific post type:

function count_user_posts_by_type( $userid, $post_type ) {
    global $wpdb;
    $where = get_posts_by_author_sql( $post_type, TRUE, $userid );
    $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    return apply_filters( 'get_usernumposts', $count, $userid );
}

// Echo Count
echo count_user_posts_by_type( $user_ID, 'reports' );

Looking for an elegant solution to limit posts by dates. For example, last week\month posts.