如果用户登录,如何在特定页面上显示父页面?

时间:2013-09-17 作者:LoveWP

我试过下面的代码,但不起作用。43是论坛页面的ID。我也在尝试使用is_user_logged_in():

function forumpage()
{
global $post;
global $wp_query;

if ($post->post_parent != 43)
{
    $thePostID = $post->post_parent;
    // echo \'You are not on the forum page\';
}
else
{
    $thePostID = $wp_query->post->ID;
    // echo \'You are at the forum page\';
}
}
add_action( \'init\' , \'forumpage\' );

1 个回复
SO网友:Milo

尚未在上查询数据库init, 没有$post$wp_query. 请参见Action Reference 对于订单,执行操作。尝试将代码移动到template_redirect 行动

结束