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;