$response =
rest_ensure_response( $results );
$response->
header( 'X-WP-Total',
$total );
$response->
header( 'X-WP-TotalPages',
$max_pages );
$request_params =
$request->
get_query_params();
$base =
add_query_arg( urlencode_deep( $request_params ),
rest_url( sprintf( '%s/%s',
$this->namespace,
$this->rest_base
) ) );
if ( $page > 1
) { $prev_link =
add_query_arg( 'page',
$page - 1,
$base );
$response->
link_header( 'prev',
$prev_link );
} if ( $page <
$max_pages ) { $next_link =
add_query_arg( 'page',
$page + 1,
$base );
$response->
link_header( 'next',
$next_link );
} return $response;
} /**
* Prepares a single search result for response.
*
* @since 5.0.0
* @since 5.6.0 The `$id` parameter can accept a string.
* @since 5.9.0 Renamed `$id` to `$item` to match parent class for PHP 8 named parameter support.
*
* @param int|string $item ID of the item to prepare.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response Response object.
*/