Set page template for all pages in wordpress with database update via functions.php

Set page template for all pages in wordpress with database update via functions.php add_action( ‘admin_init’, ‘set_page_templates’ ); function set_page_templates(){ $current_template = get_post_meta( $page->ID, ‘_wp_page_template’, true ); echo $current_template.’amit’; foreach( get_posts(‘post_type=page&posts_per_page=-1’) as $page ) { $current_template = get_post_meta( $page->ID, ‘_wp_page_template’, true ); $new_template = ‘yourtemplate.php’; if( $current_template != $new_template ) update_post_meta( $page->ID, ‘_wp_page_template’, $new_template ); } […]

How to override or change template forcefully for posts with functions.php?

add_action( ‘admin_init’, ‘set_page_templates’ ); function set_page_templates(){ $current_template = get_post_meta( $page->ID, ‘_wp_page_template’, true ); echo $current_template.’amit’; foreach( get_posts(‘post_type=post&posts_per_page=-1’) as $page ) { $current_template = get_post_meta( $page->ID, ‘_wp_page_template’, true ); $new_template = ‘yourpage-template.php’; if( $current_template != $new_template ) update_post_meta( $page->ID, ‘_wp_page_template’, $new_template ); } }

Bitnami