wp insert attachment and thumbs
-
Hi, I have small problem, my plugin do not create thumbs for my post, it upload image in media library for that post but it not create post thumb (in my media settings I have specified medium thumb 225×225). Also I need that thumb to be featured. Any help?
This is problematic part of my plugin …
$filename = $upload_dir[‘baseurl’].’/folder/’.$image_name;
$wp_filetype = wp_check_filetype(basename($filename), null );
$attachment = array(
‘post_mime_type’ => $wp_filetype[‘type’],
‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($filename)),
‘post_content’ => ”,
‘post_parent’ => $post_id,
‘post_type’ => ‘attachment’,
‘post_status’ => ‘inherit’,
‘guid’ => $filename,
);
$attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
// you must first include the image.php file
// for the function wp_generate_attachment_metadata() to work
require_once(ABSPATH . ‘wp-admin/includes/image.php’);
$attach_data =
wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
}
}
}
- The topic ‘wp insert attachment and thumbs’ is closed to new replies.