wp/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
--- a/wp/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php	Fri Sep 05 18:40:08 2025 +0200
+++ b/wp/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php	Fri Sep 05 18:52:52 2025 +0200
@@ -142,11 +142,14 @@
 
 		$ids = $result[ WP_REST_Search_Handler::RESULT_IDS ];
 
-		$results = array();
+		$is_head_request = $request->is_method( 'HEAD' );
+		if ( ! $is_head_request ) {
+			$results = array();
 
-		foreach ( $ids as $id ) {
-			$data      = $this->prepare_item_for_response( $id, $request );
-			$results[] = $this->prepare_response_for_collection( $data );
+			foreach ( $ids as $id ) {
+				$data      = $this->prepare_item_for_response( $id, $request );
+				$results[] = $this->prepare_response_for_collection( $data );
+			}
 		}
 
 		$total     = (int) $result[ WP_REST_Search_Handler::RESULT_TOTAL ];
@@ -162,7 +165,7 @@
 			);
 		}
 
-		$response = rest_ensure_response( $results );
+		$response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $results );
 		$response->header( 'X-WP-Total', $total );
 		$response->header( 'X-WP-TotalPages', $max_pages );