I’m using wp cli to import the same featured image for around 2,000 posts. I did a couple tests to see if the image would be duplicated or if WordPress would notice that the image already exists in the media library and use it. Sadly it just duplicates the image.

Command I’m using: wp media import http://example.com/wp-content/uploads/sites/30/2016/04/picture_name.jpg --post_id=x --title="Pluto Mosaic" --featured_image --url=mysite.example.com

Is there another way to do this without having to import the same image 2,000 times?

Thanks, j03

3 Answers
3

You can use wp media import to import the image once. Once you have the ID for the attachment created, you can run:

wp post list --post_type=post --format=ids | xargs -0 -d ' ' -I % wp post meta add % _thumbnail_id <thumbnail-id>

Make sure to replace <thumbnail-id> with the actual attachment ID.

Leave a Reply

Your email address will not be published. Required fields are marked *