WP_REST_Posts_Controller::handle_template() WordPress Method

The WP_REST_Posts_Controller::handle_template() method is used to render a WordPress post in the REST API. This method includes the post content, title, excerpt, and author information in the response.

WP_REST_Posts_Controller::handle_template( string $template, int $post_id, bool $validate = false ) #

Sets the template for a post.


Parameters

$template

(string)(Required)Page template filename.

$post_id

(int)(Required)Post ID.

$validate

(bool)(Optional)Whether to validate that the template selected is valid.

Default value: false


Top ↑

Source

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

	public function handle_template( $template, $post_id, $validate = false ) {

		if ( $validate && ! array_key_exists( $template, wp_get_theme()->get_page_templates( get_post( $post_id ) ) ) ) {
			$template = '';
		}

		update_post_meta( $post_id, '_wp_page_template', $template );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Added the $validate parameter.
4.7.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.