Fatalerror: Calltoamemberfunctionget () onanon-object_PHP tutorial

Source: Internet
Author: User
Fatalerror: Calltoamemberfunctionget () onanon-object. Use require (BASE_PATH.wp-load.php) in your own code's function; introduce the WordPress core code, execute WP_Query to get specific logs, and then the following error occurs: use require (BASE_PATH. 'WP-load. php '); introduce the WordPress core code, 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

This is caused by incorrect use of global variables. the default $ wp_query is defined in the wp-setting.php, because it is defined in the outermost layer, so $ wp_query is naturally a global variable. However, in your function, use require (BASE_PATH. 'WP-load. php '); introduces the WordPress core code. $ wp_query becomes the local variable in this function, so an error occurs when other code calls $ wp_query.

Solution: add the following code to the require (BASE_PATH. 'WP-load. php') code to 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;

Revoke require (BASE_PATH. wp-load.php); introduce the WordPress core code, then execute WP_Query to get the specific log, then the following error occurs :...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.