Reputation: 3285
I am creating a simple web service using WordPress without any plugin or any third party just simple php file placed in site root that receive params and connect directly to WP database via
require_once('../wp-load.php');
and query all data from database via
global $wpdb, $live_site;
$data = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '".$sessionData['userID']."' AND meta_key='last_login_time'"));
Now every thing is going well but including wp-load.php file will load all wp site with all installed plugins and lots of php files included that really not needed.
I need a way to enhance that "Web Services" by implement YAGNI (You aren't gonna need it)
Basically How to include global $wpdb, $live_site; and all wp functions without load any other unnecessary files?
Upvotes: 5
Views: 2124
Reputation: 3285
All above answers is very helpful but in my case not fit because I need a way to load data from database without load all wp plugins, themes and setting actually without
require_once('../wp-load.php');
or
require_once('../wp-config.php');
or
require_once('../wp-setting.php');
simply I have a folder in root site contains Redbeanphp lib and config.php file and my php files looks like:
require_once('config.php');
require_once 'vendor/rb.php';
global $live_site;
R::setup('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD);
$categories = R::getAll('select * from wp_term_taxonomy WHERE parent = 4);
I hope that help any one really It's pretty simple :)
Upvotes: 0
Reputation: 808
This talk has a lot of useful information about modern development in WordPress, but the most pertinent topic would be this plugin which generates a read-only JSON API.
Upvotes: 1
Reputation: 1422
I'd suggest that you check out the WordPress REST API which is proposed for Core inclusion in WordPress 3.9. This way you don't need to hack your own stuff but will get a well tested API that is maintained by the WordPress devs. From what you read the guys over at wordpress.com would like to migrate their own API to the core and they will make sure no terrible performance issues hit their servers.
Upvotes: 1