我试图对未登录的用户隐藏我的自定义帖子类型的单个页面。我使用钩子template_redirect的方法如下:
add_action('template_redirect','hide_single_property');
function hide_single_property()
{
if( is_singular('property') || is_page('dashboard')):
if( ! is_user_logged_in() ):
wp_redirect(get_permalink(103),302);
exit;
endif;
endif;
}上面的代码可以工作,但有一些问题。就像我试图访问http://example.com/property/abc一样,它会重定向到登录页面。登录后,如果我试图访问相同的帖子,它再次重定向回登录页面,但与其他属性很好。
它只是在再次登录之前加载url :(
发布于 2018-01-03 00:09:53
如果这只是你试图隐藏的一篇文章,你可以在你的sinlge-property.php模板文件中添加以下内容:
if ( is_user_logged_in() ) {
//your content file
get_template_part('content');
}
else {
//show login page
get_template_part('must-login');
}https://stackoverflow.com/questions/48062491
复制相似问题