错误:
在C:\xampp\htdocs\shop\wp-content\plugins\myplugin\viwe.php:9堆栈跟踪中调用null上的成员函数get_results():#0 {main}在C:\xampp\htdocs\shop\wp-content\plugins\myplugin\viwe.php中在线抛出
代码
global $wpdb;
$query = $wpdb->get_results('SELECT * FROM test');文件夹myplugin包含以下两个文件,
index.php
viwe.php对于文件viwe.php,代码不起作用,
C:\xampp\htdocs\shop\wp-content\plugins\myplugin\viwe.php:9堆栈跟踪中对null的成员函数get_results()的错误调用:#0 {main}在C:\xampp\htdocs\shop\wp-content\plugins\myplugin\viwe.php中在线抛出
但是index.php正在工作。
发布于 2017-02-11 16:05:54
在顶部加上这两行。
require_once($_SERVER['DOCUMENT_ROOT'] . $folder . '/wp-config.php');
require_once($_SERVER['DOCUMENT_ROOT'] . $folder . '/wp-load.php');您需要包含这些文件,以便可以调用函数get_results()。
https://stackoverflow.com/questions/42177605
复制相似问题