从命令行运行 Wordpress PHP - 专门用于 Plesk 计划任务
我需要使用 Wordpress PHP 开发一个脚本,该脚本将与 Plesk 计划任务一起运行。我在 stackoverflow 和网络上看到了一些与此相关的主题,但我似乎无法让 wordpress 或脚本工作。我对此还很陌生,所以我需要一个很好的分步指南。
基本上,我想使用命令行运行 PHP 脚本。 (执行此操作的命令是什么?...我有“php -q /path/to/file.php”,但不确定是否就是这样。)
其次,使用此脚本,我需要能够使用 Wordpress 命令,例如如 query_posts、add_post_meta、get_post_meta 等。
我在其他地方看到我需要在 php 文件顶部添加以下内容:
#!/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');
是这样吗,还是我需要更多?我假设我可以将 PHP 脚本放在我的 WordPress 根目录中并从那里运行它?
我已经让整个 PHP 部分正常工作,如果我将它包含在 Wordpress 页面中并简单地加载该页面,就可以运行它。所以我知道 WordPress 部分可以工作。
我只需要其他部分来让它处理计划的任务。 预先感谢您的所有帮助。
I need to develop a script 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,就是这样。实际上,您所需要做的就是设置
HOST_NAME
。Yes that's it. Actually, all you need to do is set
HOST_NAME
.