Fatal Error:call to a member function get () on a non-object_php tutorial

Source: Internet
Author: User
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: ...

  • 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.