I have a PHP script (that is currently a WP page), that uses WP query to loop through a custom post type, updating some values as well as uploading some images to the media library. This script works fine as a page, but since it's both quite heavy and has to be run as a cronjob, I decided to adapt it to run in the cli, but it just refuses to work.
Currently, I'm requiring the wp-load.file before my script to get WP core, as well as parsing the args, putting them into the $_REQUEST
array. The script does run but doesn't return any output (except errors if there are any), or do the actual work so I can't debug it that way.
What could be the problem and Why does it not work?
(I'm running PHP 7.2 on WHM centos with WordPress 4.9.8)
edit: I have been able to debug the script using the error_log to the point that it does run correctly and returns output when appropriate(had to populate some members of the $_SERVER array needed for wp initialization), however the wordpress loop is empty when querying for a simple custom post type. What could be the issue here?
You need to include wp-load.php
file at the top of the page.
require_once("wp-load.php");
Or
require($_SERVER['DOCUMENT_ROOT'].'/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.