If you are finding a solution to set featured image automatically in WordPress, these following code lines will help you save several minutes.
The action blow only supports setting featured image on updating a post.
The function first check if a post already has featured image. If not, it queries all images uploaded to the post and set the first uploaded image as featured one.
function my_plugin_set_feature($post_id) { if (!has_post_thumbnail($post_id)) { $attached_images = get_children("post_parent=$post_id&post_type=attachment&post_mime_type=image&numberposts=1" ); if ($attached_images) { foreach ($attached_images as $attachment_id => $attachment) { set_post_thumbnail($post_id, $attachment_id); break; } } } } add_action('save_post', 'my_plugin_set_feature');