Trying my luck once more with more smarter and awesome peeps =D

In my last question the issue was regarding getting wordpress user ID, which worked perfectly after someone steered me in the right direction.

Now I'm trying to help my friend achieve this with the same code but she doesn't get the user id no matter what we try.

The php code

require ('../wp-blog-header.php'); 

    global $current_user;

    $printID = $current_user->ID;

    echo $printID;

This gives me the ID of the user who is logged in.

I tried using the same code on her site, she's got a subfolder but that should be fine right?

require ('../Wordpress/wp-blog-header.php'); 

    global $current_user;

    $printID = $current_user->ID;

    echo $printID;

This prints out "0", doesn't matter which user that is logged in, still zero :(

Anyone got some tips? :D

  • Feels like the user is not logged in.. Can you try out print_r( wp_get_current_user() ) or simply var_dump( is_user_logged_in() _? About the sub-folder, that should be the correct path since you didn't get any errors..
    – Ismail
    Commented May 19, 2016 at 12:44
  • I tried require ('../wp-blog-header.php'); with both of those strings but it just crashed with a 500 error :( Commented May 19, 2016 at 13:00
  • My bad: print_r( wp_get_current_user() ); var_dump( is_user_logged_in() ); little syntax errors I made. Hope you're working on a local installation or you have control over your server.
    – Ismail
    Commented May 19, 2016 at 13:05
  • Your on to something @SamuelElh =D My output: WP_User Object ( [data] => stdClass Object ( [ID] => 2 [user_login] => gruffmeister[user_fname] Her output: WP_User Object ( [data] => stdClass Object ( ) [ID] => 0 [caps] => Array ( ) [cap_key] => [roles] => Array ( ) [allcaps] => Array ( ) [filter] => ) Your right, it doesn't see that I'm logged in. Cookie trouble because of the subdirectory or some login issues maybe? :S Commented May 19, 2016 at 13:22
  • 1
    Yeah, it was major confused, poor server ^^, Guess I should take a break now. Thanks again @SamuelElh =D I'd be happy to follow any social media if your active somewhere and wants some followerzzz :D Thanks man, cheers (Y) Commented May 19, 2016 at 13:51

1 Answer 1


The problem was directory related.

The Wordpress installation was in

  • htdocs/wordpress/

The functions folder with the PHP files was in

  • htdocs/functions/

So when the scripts were called upon, even if the src url was correct it wouldn't run it, I'm not sure exactly what it searched for but after moving functions inside the wordpress directory and fixing the target and action links it worked instantly.

So the new directory were

  • htdocs/wordpress/functions

Thanks to @SamuelElh once again for his support :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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