Home > Backend Development > PHP Tutorial > Fatal error: Call to a member function get() on a non-object_PHP教程

Fatal error: Call to a member function get() on a non-object_PHP教程

WBOY
Release: 2016-07-21 14:58:42
Original
921 people have browsed it

Use require(BASE_PATH . ‘wp-load.php’); in the function of your own code to introduce WordPress core code, and then execute WP_Query to obtain specific logs, 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
Copy after login

This is a problem caused by incorrect use of global variables. By default, $wp_query is defined in wp-setting.php. Because it is defined in the outermost layer, $wp_query is naturally a global variable. But here, the WordPress core code is introduced through require(BASE_PATH . 'wp-load.php'); in its own function, and $wp_query becomes a local variable in this function, so when other code calls $wp_query, it happens mistake.

The solution is: add the following code above the require(BASE_PATH . ‘wp-load.php’); code and define $wp_query as a global variable in advance:

define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/363789.htmlTechArticleUse require(BASE_PATH . wp-load.php); in the function of your own code to introduce the WordPress core code, and then Execute WP_Query to obtain specific logs, and then the following error occurs: ...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template