0

I have a few pages and I'm trying to import subpages into each like this:

 wp_insert_post (
  array(
    'post_title' => $something,
    'post_type' => 'page',
    'post_author' => 1,
    'post_status' => 'publish',
    'post_parent' => array(17, 25, 27, 29)
  )
 );

So the structure should looks like:

first->imported_name
second->imported_name
...

But this doesn't work, it creates only 1 subpage. Should I copy that code 5 times for 5 pages?

1
  • 1
    post_parent does not accept array and WP doesn't support multiple parents for posts in general. It's not clear what you are trying to do, please elaborate. – Rarst Feb 23 '14 at 16:51
0

post_parent must be a single number, not an array. Each post can have only one parent. If you want to insert posts for multiple parents, use something like this:

foreach ( array(17, 25, 27, 29) as $parent )
{
    wp_insert_post (
        array(
            'post_title'  => $something,
            'post_type'   => 'page',
            'post_author' => 1,
            'post_status' => 'publish',
            'post_parent' => $parent
        )
    );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.