Skip to content

Instantly share code, notes, and snippets.

@mrrcollins
Created March 17, 2020 08:56
Show Gist options
  • Save mrrcollins/88bb6be29e6728de74bbb11c0ae9a1fe to your computer and use it in GitHub Desktop.
Save mrrcollins/88bb6be29e6728de74bbb11c0ae9a1fe to your computer and use it in GitHub Desktop.
#!/bin/bash
# Requires wp-cli installed and a wp alias set up for each site
if [ -z ${@} ]; then
echo "Usage: createpost @SITE FILENAME"
exit
fi
site=${1}
postfile=${2}
posttitle=$(cat ${postfile} | grep ^Title | cut -d ":" -f 2 | xargs)
echo "Creating post '${posttitle}' from ${postfile}..."
wp ${site} term list category --fields=id,name,slug
echo -n "Category? "
read -e category
echo -n "Tags? "
read -e tags
echo -n "Create post (y/n)? "
read -e yesno
if [ ${yesno} == "y" ]; then
cat ${postfile} | wp ${site} post create - --post_category=${category} --post_title="${posttitle}" --tags_input="${tags}"
git mv ${postfile} ../Archive/`date +"%Y"`/
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment