Using the WordPress database outside WordPress in version 3.4+

My old workaround for using $wpdb no longer works in WordPress 3.4, but there is similar functionality built-in now. It loads a lot more than I was in my old method, but not as much as the full WordPress core being loaded.

WordPress 3.4+ Method

define( 'SHORTINIT', true );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );

Share Your Thoughts

Hi, is and , which you swear not to share with anyone, is .
If you're interested, I also have you can read at (optional).
Below are for this post:

7 Responses to “Using the WordPress database outside WordPress in version 3.4+”

  1. loncar says:

    Nice, it’s just what I have been looking for. Works with 3.5 WP. Tnx 😉

  2. Kyle says:

    Thank you so much. Super helpful.

  3. Andy says:

    Perfect. Moving my site to WordPress but have had a heck of a time using my external mySQL database that I need. This was the final piece.

  4. Andrei says:

    your tut assumes my wp installation is in server root. what if i have wp installed in ?

  5. Joan says:

    Cool! thanks, but;
    few stupid questions:
    What is ‘DOCUMENT_ROOT’? The php file? The site domain?
    Do I still need to use $wpdb prefix?
    Do I can use ordinary sql syntax or need wp api?

  6. Daniel says:

    Still works great in 3.9.1. Thanks!