Title: Get current user post count
Last modified: July 21, 2018

---

# Get current user post count

 *  Resolved [Gustav](https://wordpress.org/support/users/4ever16/)
 * (@4ever16)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/get-current-user-post-count/)
 * Im trying to get current user post count.
 *     ```
       <?php
       $current_user = wp_get_current_user();
       if ( 0 == $current_user->ID ) {
           // Not logged in.
       } else {
           Here
       }
       ?>
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [7 years, 10 months ago](https://wordpress.org/support/topic/get-current-user-post-count/#post-10514942)
 * You almost had it right in the topic title!
 * [https://codex.wordpress.org/Function_Reference/count_user_posts](https://codex.wordpress.org/Function_Reference/count_user_posts)
 *  Thread Starter [Gustav](https://wordpress.org/support/users/4ever16/)
 * (@4ever16)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/get-current-user-post-count/#post-10514971)
 * But what the correct code? I cant figure it out.
    Tested with doesnt work.
 *     ```
       <?php
       $current_user = wp_get_current_user();
       if ( 0 == $current_user->ID ) {
           // Not logged in.
       } else {
           echo $user_post_count = count_user_posts( $current_user );
       }
       ?>
       ```
   
 *     ```
       <?php
       $current_user = wp_get_current_user();
       if ( 0 == $current_user->ID ) {
           // Not logged in.
       } else {
       $userid = wp_get_current_user();
           echo $user_post_count = count_user_posts( $userid );
       }
       ?>
       ```
   
    -  This reply was modified 7 years, 10 months ago by [Gustav](https://wordpress.org/support/users/4ever16/).
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [7 years, 10 months ago](https://wordpress.org/support/topic/get-current-user-post-count/#post-10514984)
 *     ```
       <?php
       $current_user = wp_get_current_user();
       if ( 0 == $current_user->ID ) {
           // Not logged in.
          } else {
           $user_post_count = count_user_posts( $current_user->ID );
           echo $user_post_count;
       }
       ?>
       ```
   
 * should work
 *  Thread Starter [Gustav](https://wordpress.org/support/users/4ever16/)
 * (@4ever16)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/get-current-user-post-count/#post-10514985)
 * Solved it.
 *     ```
       <?php
       $current_user = wp_get_current_user();
       if ( 0 == $current_user->ID ) {
           // Not logged in.
       } else {
           echo count_user_posts( $current_user->ID );
       }
       ?>
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Get current user post count’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 2 participants
 * Last reply from: [Gustav](https://wordpress.org/support/users/4ever16/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/get-current-user-post-count/#post-10514985)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
