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
Yes, using wp-cli. Available commands;
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 includingwp-blog-header.php
in CLI mode so I don’t know for sure whether it will work, but it is definitely worth a shot.