WP_REST_Posts_Controller::handle_template( string $template, integer $post_id )

Sets the template for a post.


Description Description


Parameters Parameters

$template

(string) (Required) Page template filename.

$post_id

(integer) (Required) Post ID.


Top ↑

Source Source

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

	public function handle_template( $template, $post_id ) {
		if ( in_array( $template, array_keys( wp_get_theme()->get_page_templates( get_post( $post_id ) ) ), true ) ) {
			update_post_meta( $post_id, '_wp_page_template', $template );
		} else {
			update_post_meta( $post_id, '_wp_page_template', '' );
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
4.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.