is_author(get_current_user_id()) returns false when author id and user id match

Inside the loop, when logged in to a localhost test site as $user->ID == 1 the function is_author(get_current_user_id()) returns false when get_the_author_meta('ID') returns 1. Thus, the following conditional is never executed (is_user_logged_in() returns true):

if( is_user_logged_in() && is_author(get_current_user_id()) ) {
    // do stuff
}

Have I missed something obvious?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Are you sure you’re doing it within the loop? The is_author function checks if $wp_query is set.

Another option would be to try this:

$current_user = wp_get_current_user();

if (is_user_logged_in() && $current_user->ID == $post->post_author)  {
    // do stuff
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x