• 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

    (@npmarie)

    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.