• vestaviascott

    (@vestaviascott)


    I’d like to create a script or plug-in that I can run on every new blog I create. The purpose of the script would be to prepopulate the blog with my main post and three pages (about us, contact us, and privacy).

    I’m unsure what the wp API calls are that would be needed to insert new pages and posts into the database. Any help, much appreciated.

    The content for the about us and contact us is short and could be stored in a variable for the insert. However, the content for the privacy policy is long and will be stored in an .html file which can be parsed and then copied into the database.

    Thanks for your help!

    Alternately, It might make more sense to just create a prototype site, then create a backup of that database and use this as the basis of the new site. But I would like a script or plug-in that would update the site from the backup (without using myphpadmin, for example)

Viewing 1 replies (of 1 total)
  • MichaelH

    (@michaelh)

    If you want to change what the intial script installs, create your own install.php and put it in the wp-content folder and WordPress will use that rather than wp-admin/install.php.

    Here’s an install script that will install only the bare bones data (i.e. the default category)

    <?php
    function wp_install_defaults() {
    	global $wpdb;
    
    	// Default category
    	$cat_name = $wpdb->escape(__('Uncategorized'));
    	$cat_slug = sanitize_title(_c('Uncategorized|Default category slug'));
    	$wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$cat_name', '$cat_slug', '0')");
    	$wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('1', 'category', '', '0', '1')");
    }
    ?>

    Of course add your own inserts. See wp-admin/includes/upgrade.php for the code WordPress uses to populate posts/pages/comments/users.

Viewing 1 replies (of 1 total)
  • The topic ‘Insert a new post or page via script (blog setup)’ is closed to new replies.