• Resolved Gustav

    (@4ever16)


    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)

    (@sterndata)

    Volunteer Forum Moderator

    You almost had it right in the topic title!

    https://codex.wordpress.org/Function_Reference/count_user_posts

    Thread Starter Gustav

    (@4ever16)

    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.
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    <?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

    (@4ever16)

    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.