admin管理员组文章数量:1297200
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?
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?
Share Improve this question asked Aug 18, 2020 at 19:15 Matthew Brown aka Lord MattMatthew Brown aka Lord Matt 1,0683 gold badges13 silver badges34 bronze badges 1 |2 Answers
Reset to default 4Are 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
}
another issue might be if you are inside a WP REST API request and did not pass the X-WP-nonce header
本文标签: functionsisauthor(getcurrentuserid()) returns false when author id and user id match
版权声明:本文标题:functions - is_author(get_current_user_id()) returns false when author id and user id match 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738445235a2087178.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
is_author()
? It would return true only on author archives, e.g.example.com/author/admin
– Sally CJ Commented Aug 18, 2020 at 19:43