Run wp cli commands with cron job Run wp cli commands with cron job wordpress wordpress

Run wp cli commands with cron job


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.


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