I am running a Cron Job which requires me to load a file from one directory above my PHP script. Here is my file structure:
folder
--subfolder
--my-script.php
--header.php
--wp-load.php
--wp-config.php
I want to run my-script.php
while loading the files file-a.php
, load-it.php
and file-b.php
.
I was using the following code to load respective files:
require_once("header.php");
require_once("../wp-load.php");
require_once("../wp-config.php");
When I run the script in browser after uploading on the server or run it locally, the file paths are located correctly. However, when I run it as a Cron Job, only the header.php
is loaded.
How can I correctly load the other files so that they run properly as a Cron Job?
Update: I have tried using:
require_once(__DIR__."/wp-load.php");
as well as
require_once(__DIR__."../wp-load.php");
They both don't work.
Thanks.
In Cron you'd need to refer to the full path to get it working correctly.
This will get you wp-load if it is one directory above the current file:
require_once( dirname(__FILE__) . '/../wp-load.php' );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.