Regenerate image sizes for specific posts
I have a custom post type called
lfh_home, which uses an image size called
card-header on post listing pages.
When I make changes to that image size for testing, I want to regenerate the thumbnails/generated media, but don't want to do it to all 3000+ images on the site.
The goal here is to get the posts of the
lfh_home post type, get the ID of the featured image (stored in the
_thumbnail_id post meta field), and regenerate just the
wp media regenerate --image_size=card-header task takes approximately 12m24s to process 2971 images in local testing. This script takes 44s to process 10 images on the same machine.
chmod +x regenerate-images-for-post-type.sh
./regenerate-images-for-post-type.sh <post_type> <image_size>, where
post_typeis your post type (default 'post') and
image_sizeis an image size registered with WordPress (default 'thumbnail').