When developing WordPress Theme user center, I want to get the number of articles and comments of current logged in users, but I didn’t come up with a solution.
So Baidu searched, found a few lines of code can be done, so recorded.
//Current logined user get_current_user_id(); // perhaps global $user_id;
//Number of articles count_user_posts($user_id )
//Number of comments global $wpdb; $count_user_comments = $wpdb->get_var( $wpdb->prepare("Select count(comment_ID) from $wpdb->comments where user_id = %d", $user_id) ); var_dump($count_user_comments);