如何在自定义.php文件中包含Wordpress函数? [英] How to include Wordpress functions in custom .php file?

查看:120
本文介绍了如何在自定义.php文件中包含Wordpress函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在自定义.php文件中包含Wordpress函数?

详细信息:我的主题下有一个目录(构造函数) )命名报告。它们包含.php文件,这些文件使用DOMPDF从站点的数据生成报告以供下载。对于这些我想使用Wordpress引擎提供的功能,例如 get_the_author_meta('user_firstname',$ user_id)。如果我使用这些我得到(自然)以下错误:

In detail: I have a directory under my theme (Constructor) named reports. These contain .php files that generate reports from data from the site with DOMPDF for downloading. For these I would like to use functions that the Wordpress engine provides, for example get_the_author_meta( 'user_firstname', $user_id ). If I use these i get (naturally) the following error:


致命错误:在ROOT / public_html /中调用未定义函数get_the_author_meta()第15行的wp-content / themes / constructor / reports / testreport.php

Fatal error: Call to undefined function get_the_author_meta() in ROOT/public_html/wp-content/themes/constructor/reports/testreport.php on line 15

我认为我需要包含wp -blog-header.php。我使用 require_once(../../../../ wp-blog-header.php); 。有了这个,我收到以下404错误:

I was lead to believe that I need to include wp-blog-header.php . I use require_once("../../../../wp-blog-header.php"); . With this I get the following 404 error:


找不到网址的网页:ROOT / wp-content / themes / constructor / reports / testreport.php

No webpage was found for the web address: ROOT/wp-content/themes/constructor/reports/testreport.php

(要求指向正确的路径。如果我操作它,我会收到警告:require_once(。 ./../../wp-blog-header.php):无法打开流...所以路径必须正确。)

(The require points to the correct path. If I fiddle with it, I get Warning: require_once(../../../wp-blog-header.php): failed to open stream... So the path must be correct.)

有没什么我忽略了?为什么我不能包含这个wp文件?包含wp函数的正确方法是什么?

Is there something I overlook? Why can't I include this wp file? What is the correct method to include the wp functions?

感谢您的帮助,Sziro

Thanks for the help, Sziro

推荐答案

你在正确的轨道。试试这个:

You're on the right track. Try this instead:

require_once("../../../../wp-load.php");

这篇关于如何在自定义.php文件中包含Wordpress函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆