Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何创建一个使用wp';s函数和wp';s连接_Php_Wordpress_Rest - Fatal编程技术网

Php 如何创建一个使用wp';s函数和wp';s连接

Php 如何创建一个使用wp';s函数和wp';s连接,php,wordpress,rest,Php,Wordpress,Rest,我需要创建一个非常简单的RESTAPI(现在只获取) 但是查询表不是wordpress的原生表,那么我需要创建一个新的php文件, 这不是一个模板 那么我如何才能访问wordpress函数和wordpress连接对象,而不创建新的mysql连接对象呢 我试过了,但失败了 调用成员函数get_results() 谢谢 您可以从框架外部加载wordpress函数/对象。考虑下面的代码: define( 'SHORTINIT', true ); require_once(PATH_TO_YOUR_IN

我需要创建一个非常简单的RESTAPI(现在只获取) 但是查询表不是wordpress的原生表,那么我需要创建一个新的php文件, 这不是一个模板 那么我如何才能访问wordpress函数和wordpress连接对象,而不创建新的mysql连接对象呢

我试过了,但失败了 调用成员函数get_results() 谢谢


您可以从框架外部加载wordpress函数/对象。考虑下面的代码:

define( 'SHORTINIT', true );
require_once(PATH_TO_YOUR_INSTALLATION . '/wp-load.php' );

之后,所有已知对象(例如,
$wpdb
)都将出现。

在主题目录中创建一个新的php文件,如:

wp-content/themes/accesspress-lite-child/NEW-FILE.php 
并将下面几行放在文件顶部:

<?php
define( 'SHORTINIT', true );

//Add file from = C:\xampp\htdocs\IniYuc\
require_once('../../../wp-load.php' ); 

我的文件必须保存在哪里?实际上,我已经保存在您想要的位置,只有导入才能指定wordpress文件夹的正确路径。我添加了代码,但出现了解析错误:语法错误,意外的“全局”(T_global)在第11行的C:\xampp\htdocs\IniYuc\wp content\themes\accesspress lite child\api.php中,我添加了代码,但我继续得到相同的代码error@angel删除全局语句。我已经完成了,但现在我得到了解析错误:语法错误,意外的“全局”(T_global)在第11行的C:\xampp\htdocs\IniYuc\wp content\themes\accesspress lite child\api.php中,这与30分钟前的另一个答案有何不同?即使您安装的路径是相同的。注意文件路径,它应该包括wp根目录中的wp-load.php文件。
wp-content/themes/accesspress-lite-child/NEW-FILE.php 
<?php
define( 'SHORTINIT', true );

//Add file from = C:\xampp\htdocs\IniYuc\
require_once('../../../wp-load.php' );