Using WPDB in standalone script in wordpress

Md Riyazuddin Verified

You can use $wpdb in new .php file which is inside of theme and plugins folder, by using following code and make it standalone script without any hoo

$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$url = $_SERVER['REQUEST_URI'];
$my_url = explode('wp-content' , $url); 
$path = $_SERVER['DOCUMENT_ROOT']."/".$my_url[0];

include_once $path . '/wp-config.php';
include_once $path . '/wp-includes/wp-db.php';
include_once $path . '/wp-includes/pluggable.php';

global $wpdb;

and these all include give all permission which you want to make a standalone script in WordPress .

References and Credits

Tags

NA

Comments

Leave a Comment