WP_REST_Templates_Controller::get_items() WordPress Method

The WP_REST_Templates_Controller::get_items() method is used to get a list of templates. This method accepts two parameters: The first parameter is an array of WP_REST_Template objects. The second parameter is the WP_REST_Request object. This method returns an array of WP_REST_Template objects.

WP_REST_Templates_Controller::get_items( WP_REST_Request $request ) #

Returns a list of templates.


Parameters

$request

(WP_REST_Request)(Required)The request instance.


Top ↑

Return

(WP_REST_Response)


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php

	public function get_items( $request ) {
		$query = array();
		if ( isset( $request['wp_id'] ) ) {
			$query['wp_id'] = $request['wp_id'];
		}
		if ( isset( $request['area'] ) ) {
			$query['area'] = $request['area'];
		}
		if ( isset( $request['post_type'] ) ) {
			$query['post_type'] = $request['post_type'];
		}

		$templates = array();
		foreach ( get_block_templates( $query, $this->post_type ) as $template ) {
			$data        = $this->prepare_item_for_response( $template, $request );
			$templates[] = $this->prepare_response_for_collection( $data );
		}

		return rest_ensure_response( $templates );
	}


Top ↑

Changelog

Changelog
VersionDescription
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.