once you get your thumbnails linked, and showing, as above… there is a simple solution for “attaching” these.
I place this in my SINGLE.php file, and allow the viewer to attach them for me !
It works great with past posts, as anytime a page is viewed, like by a robot… it does the magic for me, automatically.
Once all your images are “attached” you can then delete this code if your plugins attach correctly for you. Or you can leave it, as it only acts upon checking to see if attachment is not correct before doing anything.
if (has_post_thumbnail( $post->ID ) ) {
$theid = get_post_thumbnail_id( $post->ID );
$image = wp_get_attachment_image_src( $theid , 'single-post-thumbnail' );
$attached = get_post($theid)->post_parent;
if ($attached = 0 ) {
$thumbnailURL = $image[0];
$newstring = strstr ($thumbnailURL, "20") ;
delete_post_meta($theid, '_wp_attached_file');
add_post_meta($theid, '_wp_attached_file', $newstring, true);
// Update post parent info, and sets the title of media to your post title
$my_post = array();
$my_post['ID'] = $theid;
$my_post['post_parent'] = $post->ID;
$my_post['post_title'] = get_the_title($post->ID);
// Update the post into the database
wp_update_post( $my_post );
// echo the action, for checking.
echo ' NOT ATTACHED, will attach now ->image: ' . $theid . ' url:' . $image[0] . ' post: ' . $post->ID ;
}
}