WP_REST_Templates_Controller::get_items()publicWP 5.8.0

Returns a list of templates.

{} It's a method of the class: WP_REST_Templates_Controller{}

No Hooks.

Return

WP_REST_Response.

Usage

$WP_REST_Templates_Controller = new WP_REST_Templates_Controller();
$WP_REST_Templates_Controller->get_items( $request );
$request(WP_REST_Request) (required)
The request instance.

Changelog

Since 5.8.0 Introduced.

Code of WP_REST_Templates_Controller::get_items() WP 6.0

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 );
}