从命令行调用wordpress?

发布于 2024-12-03 20:17:33 字数 849 浏览 1 评论 0原文

我想知道是否有一种方法可以从 Linux 命令行从 WordPress 调用页面(不使用 wget)。

我的意思是,我想要做的是这样的事情:

命令行:(调用一些 php 文件并传递相对 URL 作为参数)

$ php /var/www/something.php /my_blog/last_post

响应:

<div class='post'>
    <!-- the last post content -->
<div>

我已经一直在谷歌搜索并查看 WordPress 文档,但我找不到任何东西。

感谢您抽出时间!

注意:如果您熟悉 Cakephp,我想要做的是类似 外壳和任务,但对于 WordPress

解决方案:

我在 WP 文件夹的根目录中创建了一个文件,名为 command.php:

<?php
include('wp-blog-header.php');
// call the WP functions and stuff, according to the parameters
?>

来调用它:

$ php command.php my_args

I'm wondering if there's a way to call a page from wordpress from the linux command line (without using wget).

I mean, what i want is to do something like this:

The command line : (call some php file and pass a relative url as parameter)

$ php /var/www/something.php /my_blog/last_post

The response :

<div class='post'>
    <!-- the last post content -->
<div>

I've been googling and looking in the Wordpress doc but i couldn't find anything.

Thanks for your time!

Note: If you're familiar with Cakephp, what i want is to do something like the Shell & Tasks but for wordpress

Solution:

I've created a file in the root of the WP folder, called command.php:

<?php
include('wp-blog-header.php');
// call the WP functions and stuff, according to the parameters
?>

to call it:

$ php command.php my_args

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坠似风落 2024-12-10 20:17:33

是的,使用 wp-cli。可用命令;

wp core [download|config|install|install_network|version|update|update_db]
wp db [create|drop|optimize|repair|connect|cli|query|export|import]
wp eval-file
wp eval
wp export [validate_arguments]
wp generate [posts|users]
wp home
wp option [add|update|delete|get]
wp plugin [activate|deactivate|toggle|path|update|uninstall|delete|status|install]
wp post-meta [get|delete|add|update]
wp post [create|update|delete]
wp theme [activate|path|delete|status|install|update]
wp transient [get|set|delete|type]
wp user-meta [get|delete|add|update]
wp user [list|delete|create|update]

Yes, using wp-cli. Available commands;

wp core [download|config|install|install_network|version|update|update_db]
wp db [create|drop|optimize|repair|connect|cli|query|export|import]
wp eval-file
wp eval
wp export [validate_arguments]
wp generate [posts|users]
wp home
wp option [add|update|delete|get]
wp plugin [activate|deactivate|toggle|path|update|uninstall|delete|status|install]
wp post-meta [get|delete|add|update]
wp post [create|update|delete]
wp theme [activate|path|delete|status|install|update]
wp transient [get|set|delete|type]
wp user-meta [get|delete|add|update]
wp user [list|delete|create|update]
陌若浮生 2024-12-10 20:17:33

根据这个支持论坛入口,似乎没有WordPress的CLI界面。

似乎有一个 CLI 主题,但它已经过时并且不再处于积极开发状态。

但是,应该可以编写一个简单的 PHP 脚本,其中包含 wp-blog-header.php 并获取您需要的内容。我从未尝试过在 CLI 模式下包含 wp-blog-header.php,所以我不确定它是否会起作用,但它绝对值得一试。

According to this support forum entry, there doesn't seem to be a CLI interface for WordPress.

There seems to have been a CLI theme but it is outdated and no longer under active development.

However, it should be possible to write a simple PHP script that includes wp-blog-header.php and fetches the content you need. I have never tried including wp-blog-header.php in CLI mode so I don't know for sure whether it will work, but it is definitely worth a shot.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文