Tribe__Events__REST__V1__Endpoints__Term_Archive_Base::get( WP_REST_Request $request )
Handles GET requests on the endpoint.
Contents
Parameters
- $request
-
(WP_REST_Request) (Required)
Return
(WP_Error|WP_REST_Response) An array containing the data on success or a WP_Error instance on failure.
Source
File: src/Tribe/REST/V1/Endpoints/Term_Archive_Base.php
public function get( WP_REST_Request $request ) {
$request_params = array();
foreach ( $this->supported_query_vars as $origin => $destination ) {
$request_params[ $destination ] = $request[ $origin ];
}
$params = $this->parse_args( $request_params, $request->get_default_params() );
foreach ( $params as $key => $value ) {
$request->set_param( $key, $value );
}
$terms_response = $this->terms_controller->get_items( $request );
if ( $terms_response instanceof WP_Error ) {
return $terms_response;
}
$terms_data = $terms_response->get_data();
$prepared = $this->repository->prepare_terms_data( $terms_data, $this->get_taxonomy() );
$response = new WP_REST_Response();
$terms_response_headers = $terms_response->get_headers();
$data = array(
'rest_url' => $this->get_base_rest_url(),
'total' => $terms_response_headers['X-WP-Total'],
'total_pages' => $terms_response_headers['X-WP-TotalPages'],
$this->get_data_key() => $prepared,
);
$current_page = isset( $params['page'] ) ? $params['page'] : 1;
$has_next = $current_page < $data['total_pages'];
$has_previous = $current_page > 1;
if ( $has_next ) {
$data['next_rest_url'] = $this->get_next_rest_url( $data['rest_url'], $current_page );
}
if ( $has_previous ) {
$data['previous_rest_url'] = $this->get_previous_rest_url( $data['rest_url'], $current_page );
}
$response->header( 'X-TEC-Total', $data['total'], true );
$response->header( 'X-TEC-TotalPages', $data['total_pages'], true );
$response->set_data( $data );
return $response;
}