WordpressPHPFatalerror: Calltoamemberfunctionget ()

Source: Internet
Author: User
Tags wordpress php
WordpressPHPFatalerror: Calltoamemberfunctionget () onanon-object solution use require (ABSPATH. wp-load.php); Introduce the Wordpress core code, and then execute WP_Query to get a specific post, the following error will occur: PHPFatalerror: Callto

Wordpress PHP Fatal error: Call to a member function get () on a non-object solution use require (ABSPATH. 'wp-load. php '); Introduce the Wordpress core code and execute WP_Query to obtain a specific post. The following error occurs: PHP Fatal error: Call

Wordpress PHP Fatal error: Call to a member function get () on a non-object Solution


In the method of your code, use require (ABSPATH. 'wp-load. php'); Introduce the Wordpress core code and run WP_Query to obtain a specific post. The following error occurs:

PHP Fatal error:  Call to a member function get() on a non-object in /sitepath/wp-includes/query.php on line 28

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 own method, you can use require (ABSPATH. 'wp-load. php') to introduce the Wordpress core code. Instead, $ wp_query becomes the local variable of this method. Therefore, errors may occur when other code calls $ wp_query.


Solution:

Add the following code before require (ABSPATH. 'wp-load. php,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;

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.