Title: function insert_page() error
Last modified: August 19, 2016

---

# function insert_page() error

 *  [levi.putna](https://wordpress.org/support/users/leviputna-1/)
 * (@leviputna-1)
 * [17 years, 11 months ago](https://wordpress.org/support/topic/function-insert_page-error/)
 * I have a plug-in and I want it to create a page when activated, i have created
   a function (see below) that uses wp_insert_post.
 * However I get an error whenever i use it.
 *     ```
       Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/clubsdot/public_html/wp-includes/post.php on line 1284
   
       Fatal error: Call to a member function on a non-object in /home/clubsdot/public_html/wp-includes/link-template.php on line 152
       ```
   
 * If I change **post_type** to **post** it creates a new post perfectly, however
   it I use **post_type** “page” I get the error.
 * Douse anyone know what is be causing this problem?
 * **The Function**
 *     ```
       function cdc_insert_page($title, $content, $status = 'publish', $parent = '0', $order = '0') {
       global $wpdb;
   
       //test if page already exists
       $post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND post_parent = %d LIMIT 1", $title, 'page', $parent));
   
         if(!$post_name_check){
           //create page
           $postid = wp_insert_post(array(
       		'post_title' 	          => $title,
         		'post_content'  	  => $content,
         		'post_status' 	          => $status,
         		'post_author'             => 1,
                       'post_parent'             => $parent,
                       'menu_order'              => $order,
                       'post_type'               => 'page',
         		'comment_status'          => false
           ));
   
           return $postid;
         }else{
           return 0;
         }
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  [Roger Theriault](https://wordpress.org/support/users/rogertheriault/)
 * (@rogertheriault)
 * [17 years, 11 months ago](https://wordpress.org/support/topic/function-insert_page-error/#post-796647)
 * It’s telling you the file and line number where the problem is occurring… post.
   php line 1284. Looks like the $wp_rewrite object has not been set up (as a global).
   Are you calling this function on the non-admin side of things? That might be 
   why…
 * You might want to peek in xmlrpc.php (in the root dir) to see how it creates 
   a post, and what needs to be available in your environment before you can create
   the page. Or wp_admin/import/*.php

Viewing 1 replies (of 1 total)

The topic ‘function insert_page() error’ is closed to new replies.

## Tags

 * [new page](https://wordpress.org/support/topic-tag/new-page/)
 * [wp_insert_post](https://wordpress.org/support/topic-tag/wp_insert_post/)

 * 1 reply
 * 2 participants
 * Last reply from: [Roger Theriault](https://wordpress.org/support/users/rogertheriault/)
 * Last activity: [17 years, 11 months ago](https://wordpress.org/support/topic/function-insert_page-error/#post-796647)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
