• I’m trying to create a function in functions.php for my theme that will auto-create a bunch of pages and select their templates. For one of the pages, I’d like to also have the ID automatically chosen.

    I’m working with this code, but it keeps creating the page instead of just creating one page with that title.

    <?php
    $my_page = array(
    	'comment_status' => 'closed',
    	'ping_status'    => 'closed',
    	'post_content' => 'This is a new page. You can add any content you want here, including shortcodes.',
    	'post_name'      => 'auto-page',
    	'post_status' => 'publish',
    	'post_title' => 'Our New Auto-Created Page',
    	'post_type' => 'page',
    	'import_id'=>'123'
    );
    $post_id = wp_insert_post($my_page);
    ?>
    <?php update_post_meta(123, '_wp_page_template', 'page-grades.php'); ?>

    Any suggestions?

The topic ‘Auto-create pages’ is closed to new replies.