Title: Add post/page from script problem
Last modified: August 21, 2016

---

# Add post/page from script problem

 *  [andybrna](https://wordpress.org/support/users/andybrna/)
 * (@andybrna)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/add-postpage-from-script-problem/)
 * Hi,
 *  I am testing creating new pages from script on a multisite installation. I’ve
   had a google into how to go about this and am mostly using the info from this
   previous forum post:
 * [http://wordpress.org/support/topic/inserting-posts-via-external-script](http://wordpress.org/support/topic/inserting-posts-via-external-script)
 * my code looks like:
 *     ```
       <?php
   
       //      error_reporting(E_ALL); //
               ini_set('display_errors', '1');
               ini_set('display_startup_errors',1);
               error_reporting(-1);
   
       echo 'starting script';//
   
               include ('/usr/local/www3/wp-admin/load-scripts.php');
       //        include ('/usr/local/www3/wp-admin/admin.php');
               include ('/usr/local/www3/wp-includes/post.php');
            //   include ('/usr/local/www3/wp-load.php');
       //        include ('/usr/local/www3/wp-blog-header.php');
               include ('/usr/local/www3/wp-includes/ms-blogs.php');
       //        include ('/usr/local/www3/wp-includes/functions.php');
       //        include ('/usr/local/www3/wp-content/themes/mc/functions.php');
       echo 'starting script';//
   
               $wpdb->set_blog_id(15);
   
       //-- Set up post values
                       $myPost = array(
                               'post_status' => 'publish',
                               'post_type' => 'page',
                               'post_author' => 0,
                               'post_title' => 'Test Post',
                               'comment_status' => 'closed',
                               'ping_status' => 'closed',
                       );
   
       echo 'new post array defined, now create new post';
                       //-- Create the new post
                       $newPostID = wp_insert_post($myPost);
   
       ?>
       ```
   
 * This is returning no error and exits with status 0. Any “echo” I put in for debugging
   after the includes section is not executed. Probably I’m doing something basic
   wrong, can anyone help at all?
 * thanks in advance, Andy.

Viewing 1 replies (of 1 total)

 *  Thread Starter [andybrna](https://wordpress.org/support/users/andybrna/)
 * (@andybrna)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/add-postpage-from-script-problem/#post-5144332)
 * Is it worth my while trying to debug this script or is there any reason I shouldn’t
   just bypass the wordpress code all together and access the DB directly? Ie use
   Perl to do a bulk update of the DB…

Viewing 1 replies (of 1 total)

The topic ‘Add post/page from script problem’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [andybrna](https://wordpress.org/support/users/andybrna/)
 * Last activity: [11 years, 10 months ago](https://wordpress.org/support/topic/add-postpage-from-script-problem/#post-5144332)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
