Created
January 19, 2022 10:40
-
-
Save CoachBirgit/54f8880fadc3ab662a7312dfc8595305 to your computer and use it in GitHub Desktop.
Use WP-CLI on Laravel/Valet to generate some dummy content with featured images
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
#! /bin/bash | |
# Author: Birgit Olzem aka @CoachBirgit | |
# Version: 1.0 | |
# Created on: January 19th 2022 | |
# Requires WP-CLI, cURL, wget | |
### How to use | |
# Use WP-CLI on Laravel/Valet to generate some dummy content. | |
# We grab from the loremipsum.net API some dummy content. | |
# We call the Unsplash API via picsum.photos for random featured images with the image specs w1920, h1200, random, grayscale. | |
# Create a local folder where you want to download the images from Unsplash and adjust the path. | |
# run the script from your site creation script or from the WordPress instance you are working on | |
### let the magic happen! | |
# Generate some posts with lorem ipsum content | |
echo "Generate some posts" | |
curl http://loripsum.net/api/5 | wp post generate --post_content --count=10 | |
sleep 1m | |
# Download random images from Unsplash into a local folder, import them and set each as featured image related to the post | |
echo "Get POST_ID, download image and set it as featured image" | |
GET_POST_ID="$(wp post list --post_type=post --field=ID --format=csv)" | |
for post_id in ${GET_POST_ID[0]}; do | |
wget https://picsum.photos/1920/1200/\?random\&grayscale -O ~/Sites/picsum/unsplash_$post_id.jpg; | |
sleep 1m | |
wp media import ~/Sites/picsum/unsplash_$post_id.jpg --post_id=$post_id --title="A dummy picture for $post_id" --featured_image | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment