Run a WP-CLI command on every site in a multisite
wp cli run command on all sites | flush cache on all multisite sites | loop over multisite sites wp cli | wp-cli | multisite | xargsCaution: This command changes the system. Understand what it does before you run it.
wp site list --field=url --path=/var/www/vhosts/example.com/httpdocs | xargs -r -I {} wp cache flush --url={} --path=/var/www/vhosts/example.com/httpdocsFetches the URLs of all sites and runs the given command for each one with --url=. Otherwise, many WP-CLI commands only affect the main site of a multisite. The risk depends on the command used.
Note: Test write operations with a single --url= first, otherwise mistakes end up on every site.
Also searched as
- wp cli run command on all sites
- flush cache on all multisite sites
- loop over multisite sites wp cli