What I am trying to achieve
I am looking at using Wordpress decoupled, and most tutorials and guides go into detail on using the Rest API. Recently, I discovered the
SHORTINIT option to load a very minimal Wordpress instance. There is next to no documentation, and very few questions about its use, however I am interested in making use of it.
What have I tried
So far, I have setup a simple test php file in the root directory:
define('WP_DEBUG', true); define('WP_DEBUG_DISPLAY', true); //define('DOING_AJAX', true); define('SHORTINIT', true); require(dirname( __FILE__ ) . '/wp-load.php'); require( ABSPATH . WPINC . '/post.php'); die(json_encode(get_posts(array( 'numberposts' => 10, 'post_type' => 'post' ))));
Which failed because I can't access class WP_Query. After reading a few scattered examples, I gradually added more
requires but nothing seemed to work.
I have now taken a copy of wp-settings and removed things like
class-wp-rest*.php or references to the themes. The intention being to leave myself with the absolute minimum core, with enough functionality to obtain the data I need (posts, custom fields). My code now runs, and takes 1/3 of the time to load my posts compared to the
I am pre-empting people telling me just to use the REST API, but I would like to know if there is any documentation or examples for creating an endpoint URL which makes use of the
SHORTINIT, explaining which core components I need.