wp/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   140 			);
   140 			);
   141 		}
   141 		}
   142 
   142 
   143 		$ids = $result[ WP_REST_Search_Handler::RESULT_IDS ];
   143 		$ids = $result[ WP_REST_Search_Handler::RESULT_IDS ];
   144 
   144 
   145 		$results = array();
   145 		$is_head_request = $request->is_method( 'HEAD' );
   146 
   146 		if ( ! $is_head_request ) {
   147 		foreach ( $ids as $id ) {
   147 			$results = array();
   148 			$data      = $this->prepare_item_for_response( $id, $request );
   148 
   149 			$results[] = $this->prepare_response_for_collection( $data );
   149 			foreach ( $ids as $id ) {
       
   150 				$data      = $this->prepare_item_for_response( $id, $request );
       
   151 				$results[] = $this->prepare_response_for_collection( $data );
       
   152 			}
   150 		}
   153 		}
   151 
   154 
   152 		$total     = (int) $result[ WP_REST_Search_Handler::RESULT_TOTAL ];
   155 		$total     = (int) $result[ WP_REST_Search_Handler::RESULT_TOTAL ];
   153 		$page      = (int) $request['page'];
   156 		$page      = (int) $request['page'];
   154 		$per_page  = (int) $request['per_page'];
   157 		$per_page  = (int) $request['per_page'];
   160 				__( 'The page number requested is larger than the number of pages available.' ),
   163 				__( 'The page number requested is larger than the number of pages available.' ),
   161 				array( 'status' => 400 )
   164 				array( 'status' => 400 )
   162 			);
   165 			);
   163 		}
   166 		}
   164 
   167 
   165 		$response = rest_ensure_response( $results );
   168 		$response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $results );
   166 		$response->header( 'X-WP-Total', $total );
   169 		$response->header( 'X-WP-Total', $total );
   167 		$response->header( 'X-WP-TotalPages', $max_pages );
   170 		$response->header( 'X-WP-TotalPages', $max_pages );
   168 
   171 
   169 		$request_params = $request->get_query_params();
   172 		$request_params = $request->get_query_params();
   170 		$base           = add_query_arg( urlencode_deep( $request_params ), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
   173 		$base           = add_query_arg( urlencode_deep( $request_params ), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );