Skip to content

Instantly share code, notes, and snippets.

@firefly05
Last active May 20, 2021 01:27
Show Gist options
  • Save firefly05/647f36fd147e6bb693d83ce7a85fae0e to your computer and use it in GitHub Desktop.
Save firefly05/647f36fd147e6bb693d83ce7a85fae0e to your computer and use it in GitHub Desktop.
#!/bin/bash
#
TOTAL_POSTS=$(wp post list --post_type=recruiter_hub_pt --format=count)
echo "There are $TOTAL_POSTS posts in total";
# To perform a test, populate the TEST_POSTS array with the IDs of the
# posts you wish to run the scipt on.
# e.g. TEST_POSTS=(118802 118759 118655 118583);
#
# Leave TEST_POSTS array empty to run the
# script against all the posts
TEST_POSTS=();
# Switch: if there are IDs set in TEST_POSTS then perform a test run
# using those IDs. If there are no IDs in TEST_POSTS, then perform
# an actual update will all the posts
if [ "${#TEST_POSTS[@]}" -gt 0 ]; then
POST_IDS=("${TEST_POSTS[@]}")
else
POST_IDS=($(wp post list --post_type=recruiter_hub_pt --format=ids))
fi
echo "checking ${#TEST_POSTS[@]} posts...";
# Loop through each post and update the meta field
counter=0
for POST in "${POST_IDS[@]}"; do
counter=$((counter+1))
echo "updating post $counter of ${#POST_IDS[@]}..."
wp post meta update $POST confirmation_message "The latest resources, insights and inspiration are coming your way.";
echo "updated post $POST"
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment