Use require (Base_path) in the function of your own code. ' wp-load.php '); Introduce the WordPress core code, then execute wp_query to get a specific log, and then the following error occurs:
Fatal Error:call to a member function get () on a non-object in [path to site]\site\wp-includes\query.php on line 27
This is because the problem is caused by improper use of global variables, the default $WP _query is defined in wp-setting.php because it is defined in the outermost layer, so $wp _query is naturally a global variable. But here in its own function through the require (Base_path. ' wp-load.php '); The introduction of the WordPress core code, $WP _query instead becomes the local variable in this function, so other code calls $WP _query, there is an error.
The workaround is: in require (Base_path. ' wp-load.php '); Add the following code above the code to pre-define $WP _query as a global variable:
Define (' Wp_use_themes ', false); global $WP, $wp _query, $wp _the_query, $wp _rewrite, $WP _did_header;
http://www.bkjia.com/PHPjc/363789.html www.bkjia.com true http://www.bkjia.com/PHPjc/363789.html techarticle use require (Base_path. wp-load.php) in the function of your own code, introduce the WordPress core code, and then execute wp_query to get a specific log, and then the following error occurs: ...