WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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';
    $thePostID = $wp_query->post->ID;
    // echo 'You are at the forum page';
add_action( 'init' , 'forumpage' );
share|improve this question

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


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.