8

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?

zarex360
  • 312
  • 4
  • 16

2 Answers2

7

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.

Shawn H
  • 550
  • 6
  • 15
2

Absolutely.

Assuming you already have WP-CLI installed in your server, you could use something like the below line in your /etc/crontab file:

0 */12 * * * www-data wp --path=/var/www/yoursite.com db reset