【发布时间】:2019-05-17 12:08:47
【问题描述】:
我正在寻找一种在查看任何出版物时重定向的方法,但出版物的作者除外。
“作者”和“custom_role”站点中有两个角色。允许最后一个角色查看所有内容。 作者的角色只能看到他自己的,其余的重定向。 我已经尝试了一段时间,在最后一个代码中我正在工作,但它不起作用,我不知道为什么
非常感谢!
add_action( 'pre_get_posts', function() {
if( is_author() )
{
if( ! is_user_logged_in() )
{
wp_redirect( 'https://aaa.com/custom' );
exit;
}
$author = get_queried_object();
if( $author->ID != get_current_user_id() )
{
wp_redirect( get_author_posts_url(
get_current_user_id() ) );
exit;
}
}
} );
【问题讨论】: