Use WordPress functions or plugins to generate pages dynamically:
Example Code:
php
function create_programmatic_pages() {
$data = array(
array(‘title’ => ‘Hotels in New York’, ‘content’ => ‘Best hotels in New York…’),
array(‘title’ => ‘Hotels in Los Angeles’, ‘content’ => ‘Best hotels in Los Angeles…’),
);
foreach ($data as $item) {
$page = array(
‘post_title’ => $item[‘title’],
‘post_content’ => $item[‘content’],
‘post_status’ => ‘publish’,
‘post_type’ => ‘page’,
);
wp_insert_post($page);
}
}
add_action(‘init’, ‘create_programmatic_pages’);
This script creates pages dynamically using predefined data.
Leave a Reply