Call wordpress from command line?

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:

Read More

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

Related posts

Leave a Reply

2 comments

  1. 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]
    
  2. 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.