Programatically creating image attachments from local URLs and setting featured image

Answers:

Is post_guid the image location
reference? Or is the path to the image
stored somewhere else?

$post->guid is the record in a post which holds the URL for your attachment.

Where is featured image set?

featured image is saved as post meta so use update_post_meta() once you have the attachment id:

update_post_meta( $post->ID, '_thumbnail_id', $attachment_id );

Is this the best way of doing this?

Its a lot of work for several thousand posts and any way you choose will cause you some “pain” but it seems like a reasonable way of accomplishing this.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)