How am I able to call the built-in WordPress functions (specifically wp_get_user()
) in a different file (say, x.php)?
Here's my situation. If I call wp_get_current_user()
on the index.php file within my theme directory, it works just perfectly.
However, if I have x.php and called that, I got an error. I googled around, and am now including wp-load.php
(at it's correct path). Now it's just giving me an associated array with no values.
The associated array is:
WP_User Object ( [data] => [ID] => 0 [id] => 0 [caps] => Array ( ) [cap_key] => [roles] => Array ( ) [allcaps] => Array ( ) [first_name] => [last_name] => [filter] => )
I tried including index.php
in this file, and it still spits out that stuf above, instead of the correct information (which is shown by a print_r
on index.php).
Thank you!
See http://codex.wordpress.org/Integrating_WordPress_with_Your_Website
First, use either
or
and then call your WP functions.
try also including the header
<?php require('{correct_path}/wp-blog-header.php');
and if that doesn't work also try re-declaring the variables your using toglobal $var
in your wordpress setting php.