• My wordpress post is at https://www.mydomain.com/wordpressfolder/permalink
    My page is at https://www.mydomain.com/pagefolder/page.php

    I have a php include on my page that incorporates my post into my page:

    <?php include "https://www.mydomain.com/wordpressfolder/permalink/";?>

    Login is required to add a comment to the post.

    If you are logged in, and you go to the post directly, it shows you the ability to add a comment.

    If you are logged in, and you go to my page (with the include of the post), it doesn’t think you’re logged in.

    I’ve tested this by putting this code into the post (comments.php):
    <?php global $user_ID; echo('User ID: ' . $user_ID); ?>

    When logged in and you go directly to the post, it answers with the proper user ID: “User ID: 5”

    When logged in and you go to my page, it has no answer – just says “User ID: “

    So my question is how can I get my page to access the logged in user ID?

    Thanks,
    ~marc

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter etravelreviews

    (@etravelreviews)

    To clarify, When the client calls the post, the server can tell the user is logged in. When the server calls the post as an include, the server can’t tell the user is logged in.

    When accessing the post directly, with a user logged in, this test fails (as it should) – comment registration is required:

    <?php if ( get_option('comment_registration') && !$user_ID ) : ?>

    When the post is included in my page, and a user is logged in, the test validates (but it shouldn’t).

    Please help!
    ~marc

    Thread Starter etravelreviews

    (@etravelreviews)

    Perhaps it’s helpful to show you the urls:

    The post:
    https://www.etravelreviews.com/comments/savannah/

    My page:
    https://www.etravelreviews.com/savannah/

    use login: mbudda
    pw: mbudda

    Goto my page, at the bottom, click to login, and it will return you to my page after login saying you still need to login.

    If you navigate directly to the post, however after logging in, it will give you the ability to add a comment / logout.

    This hinges on the code referenced above:
    <?php if ( get_option('comment_registration') && !$user_ID ) : ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘accessing a global from an include’ is closed to new replies.