Index: src/wp-includes/query.php
===================================================================
--- src/wp-includes/query.php	(revision 36344)
+++ src/wp-includes/query.php	(working copy)
@@ -3531,6 +3531,26 @@
 		}
 
 		if ( 'ids' == $q['fields'] ) {
+
+			/**
+			 * Filter the query results when 'fields' specified in a query.
+			 *
+			 * Plugins can bypass a 'fields' query by returning
+			 * an array of posts to be returned from the query.
+			 *
+			 * @since 4.5.0
+			 *
+			 * @param array    $posts   The filtered array of posts.
+			 * @param array    $request The complete SQL query.
+			 * @param string   $fields  The query 'fields' value.
+			 * @param WP_Query &$this   The WP_Query instance (passed by reference).
+			 */
+			$this->posts = apply_filters_ref_array( 'fields_the_posts', array( false, $q['fields'], $this->request, &$this ) );
+
+			if ( false !== $this->posts ) {
+				return $this->posts;
+			}
+
 			$this->posts = $wpdb->get_col( $this->request );
 			$this->posts = array_map( 'intval', $this->posts );
 			$this->post_count = count( $this->posts );
@@ -3540,6 +3560,14 @@
 		}
 
 		if ( 'id=>parent' == $q['fields'] ) {
+
+			/** This filter is documented in wp-includes/query.php */
+			$this->posts = apply_filters_ref_array( 'fields_the_posts', array( false, $q['fields'], $this->request, &$this ) );
+
+			if ( false !== $this->posts ) {
+				return $this->posts;
+			}
+
 			$this->posts = $wpdb->get_results( $this->request );
 			$this->post_count = count( $this->posts );
 			$this->set_found_posts( $q, $limits );
Index: tests/phpunit/tests/query.php
===================================================================
--- tests/phpunit/tests/query.php	(revision 36344)
+++ tests/phpunit/tests/query.php	(working copy)
@@ -492,4 +492,68 @@
 
 		$this->assertContains( 'LIMIT 5, 5', $q->request );
 	}
+
+
+	/**
+	 * @ticket 35476
+	 *
+	 * @dataProvider data_filter_query_results_with_fields
+	 */
+	public function test_filter_query_results_with_fields( $query_params ) {
+
+		// The array we're expecting back from the filter.
+		$filtered_post_ids_array = array( 1001, 1002, 1003 );
+
+
+		// Create some posts.
+		$this->factory()->post->create_many( 10 );
+
+		add_filter( 'fields_the_posts', array( $this, 'filter_fields_the_posts' ) );
+
+		$query = new WP_Query( $query_params );
+
+		remove_filter( 'fields_the_posts', array( $this, 'filter_fields_the_posts' ) );
+
+
+		$this->assertSame( $filtered_post_ids_array, $query->posts );
+	}
+
+
+	/**
+	 * Data provider for test_filter_query_results_with_fields().
+	 *
+	 * Passes the three available options for the $notify parameter and the expected email
+	 * emails sent status as a bool.
+	 *
+	 * @return array {
+	 *     @type array {
+	 *         @type array $query_params The arguments that will be passed to WP_Query
+	 *
+	 *     }
+	 * }
+	 */
+	function data_filter_query_results_with_fields() {
+		return array(
+			array(
+				array(
+					'fields' => 'ids',
+				),
+			),
+			array(
+				array(
+					'fields' => 'id=>parent',
+				),
+			),
+		);
+	}
+
+
+	/**
+	 * Filter callback for test_filter_query_results_with_fields.
+	 *
+	 * @return array
+	 */
+	public function filter_fields_the_posts() {
+		return array( 1001, 1002, 1003 );
+	}
 }
