How to set a template with wp_insert_post
You can check this code I am able to work with this function cutom_function() { $new_page_id = wp_insert_post( array( ‘post_title’ => ‘PKB’, ‘post_type’ => ‘page’, ‘post_name’ => ‘pkb’, ‘comment_status’ => ‘closed’, ‘ping_status’ => ‘closed’, ‘post_content’ => ”, ‘post_status’ => ‘publish’, ‘post_author’ => get_user_by( ‘id’, 1 )->user_id, ‘menu_order’ => 0, // Assign page template ‘page_template’ => … Read more