Skip to content

Instantly share code, notes, and snippets.

@dasbairagya
Created September 18, 2018 07:33
Show Gist options
  • Select an option

  • Save dasbairagya/5db1d55f8ff9a4e42c97dfc529878754 to your computer and use it in GitHub Desktop.

Select an option

Save dasbairagya/5db1d55f8ff9a4e42c97dfc529878754 to your computer and use it in GitHub Desktop.
Automatically create page and assign a page template to it....
<?php
$awesome_page_id = get_option("awesome_page_id");
if (!$awesome_page_id) {
//create a new page and automatically assign the page template
$post1 = array(
'post_title' => 'Awesome Page!',
'post_content' => "",
'post_status' => "publish",
'post_type' => 'page',
);
$postID = wp_insert_post($post1, $error);
update_post_meta($postID, "_wp_page_template", "school.php");
update_option("awesome_page_id", $postID);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment