Running Wordpress PHP from command line - specifically for Plesk scheduled task
I need to develop a s开发者_Python百科cript using Wordpress PHP that will run with the Plesk Scheduled task. I've seen a few topics with this on stackoverflow and the web, but I can't seem to get the wordpress or script to work. I'm fairly new to this, so I need a good step-by-step guide.
Basically, I want to run a PHP Script using the command line. (what's the command to do this?... I had "php -q /path/to/file.php" but not sure if that's it.)
Secondly, with this script, I need to be able to use Wordpress commands such as query_posts, add_post_meta, get_post_meta, etc.
I've seen elsewhere that I need the following at the top of the php file:
#!/usr/bin/php
<?php
$_SERVER = array(
"HTTP_HOST" => "http://example.com",
"SERVER_NAME" => "http://example.com",
"REQUEST_URI" => "/",
"REQUEST_METHOD" => "GET"
);
require_once('/wp-load.php');
require_once('/wp-blog-header.php');
Is that it, or do I need more? I assume I can place the PHP script in my root Wordpress directory and run it from there?
I've got the entire PHP part working, and can run it if I include it in a Wordpress page and simply load that page. So I know the Wordpress part works.
I just need that other portion to get it working with the scheduled tasks. Thanks in advance for all your help.
Yes that's it. Actually, all you need to do is set HOST_NAME
.
精彩评论