WordPress about me page, replicate when installing new theme

What I want to do is install a template, and that template automaticly create a page, like the abotu me page is created when you first install wordpress. how can I do this? How do you run an SQL statment when you install a new theme? since pages are stored in the database I could just upload teh page this way when installing the theme but I have no ideia how.

Best Regards

Related posts

Leave a Reply

3 comments

  1. JCHASE, I agree with wp_insert_post part, the only thing that I would suggest is using an action hook instead of $_GET. Using add_action( ‘after_setup_theme’, ‘my_initiation_function’) would be a better option

  2. My above answer is for adding posts. The below answer is to add a page (it adds the page on theme activation):

    if (isset($_GET['activated']) && is_admin()){
        $new_page_title = 'This is the page title';
        $new_page_content = 'This is the page content';
        $new_page_template = ''; //ex. template-custom.php. Leave blank if you don't want a custom page template.
        //don't change the code bellow, unless you know what you're doing
        $page_check = get_page_by_title($new_page_title);
        $new_page = array(
            'post_type' => 'page',
            'post_title' => $new_page_title,
            'post_content' => $new_page_content,
            'post_status' => 'publish',
            'post_author' => 1,
        );
        if(!isset($page_check->ID)){
            $new_page_id = wp_insert_post($new_page);
            if(!empty($new_page_template)){
                update_post_meta($new_page_id, '_wp_page_template', $new_page_template);
            }
        }
    }
    
  3. This is how to do it for posts:

    global $user_ID;
    $new_post = array(
    'post_title' => 'My New Post',
    'post_content' => 'Lorem ipsum dolor sit amet...',
    'post_status' => 'publish',
    'post_date' => date('Y-m-d H:i:s'),
    'post_author' => $user_ID,
    'post_type' => 'post',
    'post_category' => array(0)
    );
    $post_id = wp_insert_post($new_post);
    

    See below for pages. See this page for the reference.