WP_REST_Posts_Controller::handle_template

Advertisement

Summery Summery

Sets the template for a post.

Syntax Syntax

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

Parameters Parameters

$template

(Required) Page template filename.

$post_id

(Required) Post ID.

$validate

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

Default value: false

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

Advertisement

Changelog Changelog

Changelog
Version Description
4.9.0 Added the $validate parameter.
4.7.0 Introduced.

Advertisement

Leave a Reply