WP_REST_Taxonomies_Controller::get_items() WordPress Method
The WP_REST_Taxonomies_Controller::get_items() method is used to retrieve a list of taxonomies. This method accepts two parameters: $request: an instance of WP_REST_Request. This parameter is required. $response: an instance of WP_REST_Response. This parameter is optional. This method returns an array of taxonomies, each represented by an object.
WP_REST_Taxonomies_Controller::get_items( WP_REST_Request $request ) #
Retrieves all public taxonomies.
Parameters
- $request
(WP_REST_Request)(Required)Full details about the request.
Return
(WP_REST_Response) Response object on success, or WP_Error object on failure.
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
public function get_items( $request ) { // Retrieve the list of registered collection query parameters. $registered = $this->get_collection_params(); if ( isset( $registered['type'] ) && ! empty( $request['type'] ) ) { $taxonomies = get_object_taxonomies( $request['type'], 'objects' ); } else { $taxonomies = get_taxonomies( '', 'objects' ); } $data = array(); foreach ( $taxonomies as $tax_type => $value ) { if ( empty( $value->show_in_rest ) || ( 'edit' === $request['context'] && ! current_user_can( $value->cap->assign_terms ) ) ) { continue; } $tax = $this->prepare_item_for_response( $value, $request ); $tax = $this->prepare_response_for_collection( $tax ); $data[ $tax_type ] = $tax; } if ( empty( $data ) ) { // Response should still be returned as a JSON object when it is empty. $data = (object) $data; } return rest_ensure_response( $data ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
4.7.0 | Introduced. |