Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Batch Create WordPress Posts via wp-cli
# Creates 30 dummy posts with featured images via
for i in {1..31}
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 --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" --allow-root;
# Update the excerpt for this item
wp post update $post_id --post_excerpt="$(curl" --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 "";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.