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!
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 to global $var
in your wordpress setting php.
See http://codex.wordpress.org/Integrating_WordPress_with_Your_Website
First, use either
<?php define('WP_USE_THEMES', false); require('./wp-blog-header.php'); ?>
or
<?php require('/the/path/to/your/wp-blog-header.php');?>
and then call your WP functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With