Spent most of yesterday working on a script that interfaces with WordPress to update posts as it runs. It wasn’t a big part of the script, but it was the part that caused the most frustration.
When I was testing locally, I was running the script through a web browser and everything worked perfectly. But ultimately this script needed to run through cron, and when I tried to run through the command line nothing happened.
I was able to trace it to something WordPress related because the script would work up until I included the wp-load.php file. And then it just stopped.
Turns out it was a very simple fix. WordPress needed $_SERVER[‘HTTP_HOST’] set, and it’s not from the command line. Adding $_SERVER[‘HTTP_HOST’] = ‘example.com’ to the line above the wp-load.php include fixed it so the script ran.
This was on a network enabled version of WordPress, so that might make a difference.
Now I just need to figure out how to work around the WordPress include changing the timezone from CST to GMT, so if there are any suggestions on that…