Using wpdb without loading all plug-ins via wp-load.php

I'm trying to prevent WP from loading all plug-ins when including wp-load.php, since I don't really need them nor the usual WP actions/filters. All I need is the WPDB class to query the database easily.

I've only found an (old) solution that involves defining WP_INSTALLING to trick WP into not loading plug-ins, but I'm not sure if it still works on current versions and/or if there's a better way.

(Background: I'm trying to optimize a simple autocomplete PHP script that serves JSON results via AJAX by doing some simple queries after initializing $wpdb via wp-load.php)

Topic wp-load.php ajax wpdb plugins Wordpress

Category Web


WordPress 3.4+ Method: Just define this define( 'SHORTINIT', true ); before you call wp-load.php


WordPress is heavy out-of-the-box. If you only need the database, you'd be so much better off using mysqli or PDO and just connecting directly.

Not to mention (in my opinion) PDO beats hell out of wpdb anyway, win win.

the idea is to make use of the DB defines in wp-config.php without needing to store the username/password somewhere else

Create wp-config-db.php with just your database constants, then swap them out in wp-config.php for require './wp-config-db.php';

Now you can just load wp-config-db.php in your handler and hey presto.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.