I'm trying to write some code to access the WordPress database. Everything tells me to load wp-load.php to do this. However I just get critical errors when I do. This used to work a couple of months back, not sure when it stopped working, so might be a recent WordPress update that has stopped this working. Currently on WordPress 6.1.1
<?php
ini_set( 'display_errors', '1' );
ini_set( 'display_startup_errors', '1' );
error_reporting( E_ALL );
global $_SERVER;
$_SERVER['HTTP_HOST'] = 'www.mydomain.com';
$_SERVER['REQUEST_URI'] = '/';
$file_require = $_SERVER["DOCUMENT_ROOT"] . '/wp-load.php';
include $file_require;
if (file_exists( $file_require )) {
echo 'FILE EXISTS: file_require: ' . $file_require . '<br>';
} else {
echo 'FILE NOT FOUND: file_require: ' . $file_require . '<br>';
}
echo 'Successfully Loaded wp-load.php<br>';
The code after the include nevers gets executed. Just get a "There has been a critical error on this website."
The site is a MULTISITE and some articles and similar questions do suggest that this may be teh cuase. But this used to work just fine and this has always been a multisite. As I say, this has stopped working during the last few weeks.
Any help would be gratefully received.