I am looking for a way to generate featured image per post based on the first image in the post for old posts without a set featured image. I'm switching from handmade thumbnails to auto generated featured images. With new posts I got this working, but I don't want to set a featured image of my other 2000 posts by hand. Found some plugins, but they aren't working well or not supported and the info I did find here is all about setting the image with new posts. Any hook, script or function for this? Anyone got an idea?


You can look into this post: http://ken.ph/first-image-of-wordpress-post-as-thumbnail/

Or if you're comfortable with MySql try using this (obviously check it on local database first):

INSERT into wp_postmeta (meta_value, meta_key, post_id) 
SELECT DISTINCT(ID), post_type , post_parent 
FROM wp_posts 
WHERE post_type= 'attachment' 
AND post_parent !=0 
AND post_status='inherit';
UPDATE wp_postmeta set meta_key = '_thumbnail_id' 
WHERE meta_key='attachment'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.