Search code examples
wordpresscronwp-cli

Run wp cli commands with cron job


Is it possbile to run WP cli commands with a cron job? Because I'm setting up a demo site, and want the site to be reset every 12 hour. And i thought that with wp cli, i can reset the installation. Import a file with the right content and so on.

Or do you guys have any better idea how to do this?


Solution

  • Yes, you can.

    Here's a line from my crontab file. (You can edit it by running crontab -e)

    */10 * * * * /var/www/vendor/wp-cli/wp-cli/bin/wp --path=/var/www/ update-credits

    This runs my WP-CLI command update-credits every 10 minutes.

    NOTE: I'm using WP-CLI as a Composer dependency in that website. The path to your wp binary may vary.