WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Comparing the post author ID and logged in user ID

[Resolved] Comparing the post author ID and logged in user ID

  • cip6791
    Participant

    @cip6791

    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

Viewing 1 replies (of 1 total)
  • cip6791
    Participant

    @cip6791

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

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Comparing the post author ID and logged in user ID’ is closed to new replies.