Most current WordPress themes support featured images. But, let’s say you’re updating a site that uses a theme built before WordPress 3.0. And let’s say that theme uses a custom meta field to define the featured images. And let’s say there’s over 900 posts on the site. There’s no way you’d want to set all those featured images manually.
I found myself in that situation today- so I wrote a little plugin:
1) It checks if the custom meta field (‘FeaturedImage’) is set, and if so, fetches the attachment id based on the url string. That attachment gets set as the featured image.
2) If the custom meta field is not set, it will use the first attachment image it finds.
The majority of the code was lifted from two places. Gavick posted the code about setting featured images. Philip posted the code about fetching attachment ids from URL strings.
I can’t vouch at all for the quality of this plugin- so I’m just putting it on GitHub in case it can save another developer some time. Or maybe even make it a little better. Pull requests welcome.
Finally, this saved me so much headache. Every other script I attempted left me wanting to give up. Thank you so much.
Sorry, as I’m no developer, may I ask you to write a little function (on the false-line of this) that pulls a custom field value and makes it the featured image of the post? I’d appreciate. Criss (Italy)