Created
January 26, 2019 11:03
-
-
Save craigiswayne/38863a29260b3e37c87e2660f8255f00 to your computer and use it in GitHub Desktop.
Batch Create WordPress Posts via wp-cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# Creates 30 dummy posts with featured images via placeimg.com | |
### | |
POST_TYPE_SLUG=post; | |
POST_TYPE_SINGULAR_NAME=Post; | |
for i in {1..31} | |
do | |
echo "Creating $POST_TYPE_SINGULAR_NAME i = [$i]"; | |
post_id=$(wp post create --post_name="Entrant $i" --post_title="Entry $i" --post_type="$POST_TYPE_SLUG" --post_status=publish --post_author=1 --post_date="1987-10-$i 00:00:00" --porcelain --allow-root); | |
echo "post_id = [$post_id]"; | |
# Download and attach a featured image to the this Bike | |
wp media import https://placeimg.com/640/480/people.jpeg --post_id=$post_id --featured_image --caption="Image Caption for $POST_TYPE_SINGULAR_NAME $i" --desc="Description for $POST_TYPE_SINGULAR_NAME $i" --allow-root; | |
# Update the post content with some random stuff | |
wp post update $post_id --post_content="$(curl https://loripsum.net/api/5/verylong/decorate/link/ul/ol/dl/bq/code/headers)" --allow-root; | |
# Update the excerpt for this item | |
wp post update $post_id --post_excerpt="$(curl https://loripsum.net/api/1/short/decorate/)" --allow-root; | |
# Give the Bike some meta data | |
echo "Adding meta data to post [$i]"; | |
wp post meta update $post_id credit "Created automatically using wp-cli" --allow-root; | |
echo "----------------------------------" | |
echo ""; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment