Index: src/wp-includes/post.php
===================================================================
--- src/wp-includes/post.php	(revision 38260)
+++ src/wp-includes/post.php	(working copy)
@@ -3260,13 +3260,24 @@
 	}
 
 	// Set or remove featured image.
-	if ( isset( $postarr['_thumbnail_id'] ) && ( post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type ) ) {
-		$thumbnail_id = intval( $postarr['_thumbnail_id'] );
-		if ( -1 === $thumbnail_id ) {
-			delete_post_thumbnail( $post_ID );
-		} else {
-			set_post_thumbnail( $post_ID, $thumbnail_id );
+	if ( isset( $postarr['_thumbnail_id'] ) ) {
+		$thumbnail_support = post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type;
+		if ( ! $thumbnail_support && 'attachment' === $post_type && $post_mime_type ) {
+			if ( wp_attachment_is( 'audio', $post_ID ) ) {
+				$thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' );
+			} elseif ( wp_attachment_is( 'video', $post_ID ) ) {
+				$thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' );
+			}
 		}
+
+		if ( $thumbnail_support ) {
+			$thumbnail_id = intval( $postarr['_thumbnail_id'] );
+			if ( -1 === $thumbnail_id ) {
+				delete_post_thumbnail( $post_ID );
+			} else {
+				set_post_thumbnail( $post_ID, $thumbnail_id );
+			}
+		}
 	}
 
 	if ( ! empty( $postarr['meta_input'] ) ) {
Index: tests/phpunit/tests/post/thumbnails.php
===================================================================
--- tests/phpunit/tests/post/thumbnails.php	(revision 38260)
+++ tests/phpunit/tests/post/thumbnails.php	(working copy)
@@ -233,4 +233,77 @@
 
 		$this->assertEquals( wp_get_attachment_url( self::$attachment_id ), $actual );
 	}
+
+	/**
+	 * @ticket 12922
+	 */
+	function test__wp_preview_post_thumbnail_filter() {
+		$post_id = self::factory()->post->create();
+
+		$_REQUEST['_thumbnail_id'] = self::$attachment_id;
+
+		$result = _wp_preview_post_thumbnail_filter( '', $post_id, '_thumbnail_id' );
+		$this->assertEquals( self::$attachment_id, $result );
+	}
+
+	/**
+	 * @ticket 12922
+	 */
+	function test_insert_post_with_post_thumbnail() {
+		$post_id = wp_insert_post( array(
+			'post_status' => 'publish',
+			'post_content' => rand_str(),
+			'post_title' => rand_str(),
+			'_thumbnail_id' => self::$attachment_id,
+		) );
+
+		$thumbnail_id = get_post_thumbnail_id( $post_id );
+		$this->assertEquals( self::$attachment_id, $thumbnail_id );
+
+		$post_id = wp_insert_post( array(
+			'ID' => $post_id,
+			'post_status' => 'publish',
+			'post_content' => rand_str(),
+			'post_title' => rand_str(),
+			'_thumbnail_id' => -1, // -1 removes post thumbnail.
+		) );
+
+		$thumbnail_id = get_post_thumbnail_id( $post_id );
+		$this->assertEmpty( $thumbnail_id );
+	}
+
+	/**
+	 * @ticket 37658
+	 */
+	function test_insert_attachment_with_post_thumbnail() {
+		// Audio files support featured images.
+		$post_id = wp_insert_post( array(
+			'post_type' => 'attachment',
+			'post_status' => 'publish',
+			'post_content' => rand_str(),
+			'post_title' => rand_str(),
+			'post_mime_type' => 'audio/mpeg',
+			'post_parent' => 0,
+			'file' => DIR_TESTDATA . '/images/canola.jpg',
+			'_thumbnail_id' => self::$attachment_id,
+		) );
+
+		$thumbnail_id = get_post_thumbnail_id( $post_id );
+		$this->assertEquals( self::$attachment_id, $thumbnail_id );
+
+		// Images do not support featured images.
+		$post_id = wp_insert_post( array(
+			'post_type' => 'attachment',
+			'post_status' => 'publish',
+			'post_content' => rand_str(),
+			'post_title' => rand_str(),
+			'post_mime_type' => 'image/jpeg',
+			'post_parent' => 0,
+			'file' => DIR_TESTDATA . '/images/canola.jpg',
+			'_thumbnail_id' => self::$attachment_id,
+		) );
+
+		$thumbnail_id = get_post_thumbnail_id( $post_id );
+		$this->assertEmpty( $thumbnail_id );
+	}
 }
