Index: src/wp-includes/comment.php
===================================================================
--- src/wp-includes/comment.php	(revision 38350)
+++ src/wp-includes/comment.php	(working copy)
@@ -2266,23 +2266,27 @@
 function do_all_pings() {
 	global $wpdb;
 
+	$post_types = get_post_types( array( 'publicly_queryable' => true ) );
+
 	// Do pingbacks
-	while ($ping = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
-		delete_metadata_by_mid( 'post', $ping->meta_id );
+	$pings = get_posts( array( 'post_type' => $post_types, 'suppress_filters' => false, 'posts_per_page' => -1, 'meta_value' => '_pingme' ) );
+	foreach ( $pings as $ping ) {
+		delete_post_meta( $ping->ID, '_pingme' );
 		pingback( $ping->post_content, $ping->ID );
 	}
 
 	// Do Enclosures
-	while ($enclosure = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
-		delete_metadata_by_mid( 'post', $enclosure->meta_id );
+	$enclosures = get_posts( array( 'post_type' => $post_types, 'suppress_filters' => false, 'posts_per_page' => -1, 'meta_value' => '_encloseme' ) );
+	foreach ( $enclosures as $enclosure ) {
+		delete_post_meta( $enclosure->ID, '_encloseme' );
 		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);
+	$trackbacks = get_posts( array( 'post_type' => $post_types, 'suppress_filters' => false, 'posts_per_page' => -1, 'to_ping' => true, 'fields' => 'ids' ) );
+	foreach ( $trackbacks as $trackback ) {
+		do_trackbacks( $trackback );
+	}
 
 	//Do Update Services/Generic Pings
 	generic_ping();
Index: src/wp-includes/query.php
===================================================================
--- src/wp-includes/query.php	(revision 38350)
+++ src/wp-includes/query.php	(working copy)
@@ -1577,6 +1577,7 @@
 	 *     @type array        $tax_query               An associative array of WP_Tax_Query arguments.
 	 *                                                 See WP_Tax_Query->queries.
 	 *     @type string       $title                   Post title.
+	 *     @type string       $to_ping                 Post ping status. Default false.
 	 *     @type bool         $update_post_meta_cache  Whether to update the post meta cache. Default true.
 	 *     @type bool         $update_post_term_cache  Whether to update the post term cache. Default true.
 	 *     @type bool         $lazy_load_term_meta     Whether to lazy-load term meta. Setting to false will
@@ -1621,6 +1622,7 @@
 		$qv['pagename'] = trim( $qv['pagename'] );
 		$qv['name'] = trim( $qv['name'] );
 		$qv['title'] = trim( $qv['title'] );
+
 		if ( '' !== $qv['hour'] ) $qv['hour'] = absint($qv['hour']);
 		if ( '' !== $qv['minute'] ) $qv['minute'] = absint($qv['minute']);
 		if ( '' !== $qv['second'] ) $qv['second'] = absint($qv['second']);
@@ -2565,6 +2567,9 @@
 			else
 				$q['post_type'] = '';
 		}
+		if ( ! isset( $q['to_ping'] ) ) {
+			$q['to_ping'] = false;
+		}
 		$post_type = $q['post_type'];
 		if ( empty( $q['posts_per_page'] ) ) {
 			$q['posts_per_page'] = get_option( 'posts_per_page' );
@@ -3093,6 +3098,10 @@
 			$post_type_object = get_post_type_object ( 'post' );
 		}
 
+		if ( $q['to_ping'] ) {
+			$where .= " AND {$wpdb->posts}.to_ping <> ''";
+		}
+
 		$edit_cap = 'edit_post';
 		$read_cap = 'read_post';
 
Index: tests/phpunit/tests/post/query.php
===================================================================
--- tests/phpunit/tests/post/query.php	(revision 38350)
+++ tests/phpunit/tests/post/query.php	(working copy)
@@ -388,7 +388,25 @@
 		$actual_posts = $q->get_posts();
 		$this->assertEqualSets( $requested, $actual_posts );
 	}
+	
+	/**
+	 * Tests the to_ping attribute of WP_Query.
+	 *
+	 * @ticket 36824
+	 */
+	public function test_to_ping() {
+		$q = new WP_Query();
 
+		$post_ids[0] = self::factory()->post->create( array( 
+						'to_ping' => 'http://www.example.com' ) ); 
+		$q->query( array(
+				'to_ping' => '',
+				'fields' => 'ids' ) );
+		$actual_posts = $q->get_posts();
+		$this->assertSame( $post_ids, $actual_posts );
+	}
+
+
 	/**
 	 * @ticket 36687
 	 */
