Title: wp_insert_post() returns null
Last modified: August 15, 2017

---

# wp_insert_post() returns null

 *  [npmarie](https://wordpress.org/support/users/npmarie/)
 * (@npmarie)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/wp_insert_post-returns-null/)
 * I am creating a page and some childpages, using wp_insert_post(), whenever a 
   post is made in a custom post type. the pages are created just fine however wp_insert_post()
   does not return the id of the childpages, instead it returns null.
 *  $mainparr = array(
    ‘post_title’ => $value, ‘post_status’ => ‘publish’, ‘post_type’
   => ‘page’, ‘post_content’ => ‘ ‘, ‘comment_status’ => ‘closed’, ‘post_name’ =
   > $course_slug, ‘menu_order’ => 0, ); $mainp_id=wp_insert_post( $mainparr, false);
 *  update_post_meta($post->ID,’course_page_id’,$mainp_id);
    $dokarr = array( ‘post_title’
   => ‘Dokumenter’, ‘post_status’ => ‘publish’, ‘post_type’ => ‘page’, ‘post_content’
   => ‘ ‘, ‘comment_status’ => ‘closed’, ‘post_name’ => ‘dokumenter’, ‘post_parent’
   => $mainp_id, ‘menu_order’ => 0, ); $dokid = wp_insert_post( $dokarr, false );
 * the $mainp_id is returned just fine however any childpages like $dokid return
   null, what am I doing wrong?

Viewing 1 replies (of 1 total)

 *  Thread Starter [npmarie](https://wordpress.org/support/users/npmarie/)
 * (@npmarie)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/wp_insert_post-returns-null/#post-9410805)
 * nevermind I found the error.
    wp_insert_post_does return the id, i had a different
   function overriding the value of the id before it was output, my bad.

Viewing 1 replies (of 1 total)

The topic ‘wp_insert_post() returns null’ is closed to new replies.

## Tags

 * [$post->id](https://wordpress.org/support/topic-tag/post-id/)
 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [wp_insert_post](https://wordpress.org/support/topic-tag/wp_insert_post/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 1 participant
 * Last reply from: [npmarie](https://wordpress.org/support/users/npmarie/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/wp_insert_post-returns-null/#post-9410805)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
