A site I have inherited uses custom fields to set a path for thumbnails. Ideally I'd like to switch this over to use the built in post-thumbnail. Is there a way to procedurally set the post-thumbnail?
Thanks
|
A site I have inherited uses custom fields to set a path for thumbnails. Ideally I'd like to switch this over to use the built in post-thumbnail. Is there a way to procedurally set the post-thumbnail? Thanks |
|||||
|
|
The issue is going to be the difference in the data required for setting the post thumbnail (an attachment ID) and what's probably in the custom field: a URL. The way I'm going to suggest is very sloppy: adds more attachments to WordPress. A better way might be to write a custom SQL query where you grab the attachment ID from the custom field URL. This works, it just might not be the best way. First, get all the posts:
Then we'll loop through them, grabbing the original Image URL, then inserting it as a new attachment. Finally, we'll update the postmeta table to reflect our new thumbnail ID and get rid of the old post thumbnail custom field.
That's it! Here it is as a plugin: http://pastie.org/2386814 |
|||
|
|