Files
NAN_Student_Handbook/includes/back-end/template_content_update.php
2024-01-18 18:54:23 -05:00

55 lines
1.3 KiB
PHP

<?php
// function update_page_content_from_file()
// {
// // Get all pages
// $pages = get_pages();
// foreach ($pages as $page) {
// $slug = $page->post_name;
// $file_path = get_template_directory() . '/templates/internal/' . $slug . '.php';
// // Check if the file exists
// if (file_exists($file_path)) {
// // Read the content from the file
// $file_content = file_get_contents($file_path);
// // Update the page content
// wp_update_post(array(
// 'ID' => $page->ID,
// 'post_content' => $file_content,
// ));
// }
// }
// }
function update_page_content_from_file()
{
// Get all pages
$pages = get_pages();
foreach ($pages as $page) {
$slug = $page->post_name;
$file_path = get_template_directory() . '/templates/internal/' . $slug . '.php';
// Check if the file exists
if (file_exists($file_path)) {
// Start output buffering to capture PHP output
ob_start();
// Include the file to execute its PHP code
include($file_path);
// Get the output and clean the output buffer
$file_content = ob_get_clean();
// Update the page content
wp_update_post(array(
'ID' => $page->ID,
'post_content' => $file_content,
));
}
}
}