WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Comparing the post author ID and logged in user ID (2 posts)

  1. cip6791
    Member
    Posted 3 years ago #

    I am trying to display a message if the user that is logged in is the author of the post. I am doing something wrong below. I logged in with a different user, the IDs change but I stil get the message "You are the author of this post". Any ideas?

    <?php $getid = $posts[0]->post_author; ?>
    
    <?php echo 'Hello: ' . $getid; ?>
    
    <?php global $current_user;
          get_currentuserinfo();
    
          echo 'Hi: ' . $current_user->display_name . "\n";
          echo 'your user ID is: ' . $current_user->ID . "\n";
    ?>
    
    <?php if ($getid == $current_user->ID);
    
    echo "You are the author of this post";
    
    ?>

    Thank you

  2. cip6791
    Member
    Posted 3 years ago #

    <?php if ($getid == $current_user->ID){
    
    echo "You are the author of this post";
    
    }
    else
    {
    
    echo "You are not the author of this post";
    
    }
    
    ?>

    I got it

Topic Closed

This topic has been closed to new replies.

About this Topic