Skip to content

Instantly share code, notes, and snippets.

@PatelUtkarsh
Last active July 10, 2016 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatelUtkarsh/3c50655d3606943b5801652a6aaa5634 to your computer and use it in GitHub Desktop.
Save PatelUtkarsh/3c50655d3606943b5801652a6aaa5634 to your computer and use it in GitHub Desktop.
Running wp-cron with wp-cli
#!/bin/bash
WP_PATH="/path/to/wp"
# Check for WP-CLI
if ! hash wp 2>/dev/null; then
echo "WP-CLI is not available"
exit
fi
# Fall back if no WP.
if ! $(wp core is-installed --path="$WP_PATH" --quiet); then
echo "Wrong path maybe? No wordpress installtion found: ${WP_PATH}"
exit
fi
# Get a list of site URLs
if $(wp core is-installed --path="$WP_PATH" --quiet --network);
then
SITE_URLS=`wp site list --fields=url --archived=0 --deleted=0 --format=csv --path="$WP_PATH" | sed 1d`
else
SITE_URLS=(`wp option get siteurl --path="$WP_PATH"`)
fi
# Loop all sites
for SITE_URL in $SITE_URLS
do
wp cron event run $( wp cron event list --fields=hook,next_run_relative --format=csv --url="$SITE_URL" --path="$WP_PATH" | awk -F, '$2=="now" {print $1}' ) --url="$SITE_URL" --path="$WP_PATH" --quiet
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment