Sets the template for a post.
Parameters
$template
stringrequired- Page template filename.
$post_id
intrequired- Post ID.
$validate
booloptional- Whether to validate that the template selected is valid.
Default:
false
Source
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 );
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.