0

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' );
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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