如何在自定义 .php 文件中包含 WordPress 函数?
详细说明:我的主题(构造函数)下有一个名为报告的目录。这些包含 .php 文件,这些文件使用 DOMPDF 从站点的数据生成报告以供下载。对于这些,我想使用 WordPress 引擎提供的功能,例如get_the_author_meta( 'user_firstname', $user_id )
. 如果我使用这些,我(自然)会得到以下错误:
致命错误:在第 15 行的 ROOT/public_html/wp-content/themes/constructor/reports/testreport.php 中调用未定义函数 get_the_author_meta()
我被引导相信我需要包含 wp-blog-header.php 。我用require_once("../../../../wp-blog-header.php");
. 有了这个我得到以下404错误:
没有找到该网址的网页:ROOT/wp-content/themes/constructor/reports/testreport.php
(需要指向正确的路径。如果我摆弄它,我会收到警告:require_once(../../../wp-blog-header.php): failed to open stream... 所以路径必须是正确的。)
有什么我忽略的吗?为什么我不能包含这个 wp 文件?包含 wp 函数的正确方法是什么?
感谢您的帮助,西罗