I'm developing a wordpress plugin for Wordpress. I produced an easy PHP file:

Test.php. I'm able to access that via browser however when I actually do:

<?php

global $wpdb;
global $wp;

?>

My wpdb and wordpress are NULL. Can anybody let me know what could possibly be the problem? In a nutshell all wordpress functions are null. When does wordpress library really set them? Normally your wordpress plugin will run in context of Wordpress and you've got exactly the same menu of Wordpress on left etc. However I need 1 file during my PHP which does not run in context of Wordpress but I have to access wordpress functions. It's a simple PHP file that ought to return just XML not one other HTMl etc.

The problem is the fact that individuals variables aren't set. So that they are NULL.

Should you set them first, they will not be NULL.

Try such as the wp-load.php file prior using these global variables and find out in the event that fits you are needs.

See too:

Code:

//This path assumes your php file is in the template dir, you may need to update the path to these files.

include_once('../../../wp-load.php');

Source: http://stackoverflow.com/a/4035357/835950