diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php
index 4b192ea02e..6b76ff4f2a 100644
--- a/src/wp-includes/comment.php
+++ b/src/wp-includes/comment.php
@@ -2645,12 +2645,20 @@ function do_all_pings() {
 		do_enclose( $enclosure->post_content, $enclosure->ID );
 	}
 
-	// Do Trackbacks
-	$trackbacks = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'" );
-	if ( is_array( $trackbacks ) ) {
-		foreach ( $trackbacks as $trackback ) {
-			do_trackbacks( $trackback );
-		}
+	// Do trackbacks.
+	$trackbacks = get_posts(
+		array(
+			'post_type'        => get_post_types(),
+			'suppress_filters' => false,
+			'nopaging'         => true,
+			'meta_key'         => '_trackbackme',
+			'fields'           => 'ids',
+		)
+	);
+
+	foreach ( $trackbacks as $trackback ) {
+		delete_post_meta( $trackback, '_trackbackme' );
+		do_trackbacks( $trackback );
 	}
 
 	//Do Update Services/Generic Pings
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index 15422a5f32..56b7317c6f 100644
--- a/src/wp-includes/post.php
+++ b/src/wp-includes/post.php
@@ -6786,6 +6786,11 @@ function _publish_post_hook( $post_id ) {
 	}
 	add_post_meta( $post_id, '_encloseme', '1' );
 
+	$to_ping = get_to_ping( $post_id );
+	if ( ! empty( $to_ping ) ) {
+		add_post_meta( $post_id, '_trackbackme', '1' );
+	}
+
 	if ( ! wp_next_scheduled( 'do_pings' ) ) {
 		wp_schedule_single_event( time(), 'do_pings' );
 	}
