Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have tried with the code bellow, but it's not working. 43 is the ID of the forum page. Also I'm trying to use 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' );
share|improve this question

1 Answer 1

The database hasn't been queried yet on init, there is no $post or $wp_query. See the Action Reference for the order actions are executed. Try moving your code to the template_redirect action.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.