WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

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'
share|improve this answer
Thanks! This will get me going! – AKNL Oct 18 '12 at 8:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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