I am trying to connect to Wordpress using the WPDB because it's such a beautiful class and also there are configurations that specified in wp-config.php so i won't need to specify it again.
I going to write a small separated script from main wordpress to run in background that will need to use this WPDB instance.
How can I archive this?
Any help is appreciated.
Following two steps are enough.
any global variables you can use in this page after that. Make sure you give the correct include path of wp-blog-header.php. No need to include several files.
This should do the trick too:
Fast and lightweight way with just a single line is
require(dirname(_FILE__).'/wp-blog-header.php');
Reason is because wordpress initializes loading the index.php and when you check the index.php , you see :
require(dirname(__FILE__).'/wp-blog-header.php');
This loads and bootstrap wordpress.
so to use wordpress outside of the wordpress install , simply create a new file and then write :
require(dirname(__FILE__).'/wp-blog-header.php');
then for a test, write : global $wpdb; var_export($wpdb) .
so now you have access to all wordpress API and the database object $wpdb.