admin管理员组

文章数量:1416333

I have an array of image id's and i want assign them to the specific post:

foreach ($image_ids as  $image_id)
    var_dump(wp_insert_post(array('ID' => $image_id, 'post_parent' => $new_post_id), TRUE));

But there occurs error:

object(WP_Error)#252 (2) {
  ["errors"]=>
  array(1) {
    ["empty_content"]=>
    array(1) {
      [0]=>
      string(38) "Content, title, and excerpt are empty."
    }
  }
  ["error_data"]=>
  array(0) {
  }
}

So is it possible to update the post_parent without updating other data?

I have an array of image id's and i want assign them to the specific post:

foreach ($image_ids as  $image_id)
    var_dump(wp_insert_post(array('ID' => $image_id, 'post_parent' => $new_post_id), TRUE));

But there occurs error:

object(WP_Error)#252 (2) {
  ["errors"]=>
  array(1) {
    ["empty_content"]=>
    array(1) {
      [0]=>
      string(38) "Content, title, and excerpt are empty."
    }
  }
  ["error_data"]=>
  array(0) {
  }
}

So is it possible to update the post_parent without updating other data?

Share Improve this question asked Jan 9, 2013 at 22:36 user1692333user1692333 4472 gold badges9 silver badges17 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 10

Use wp_update_post(), not insert.

wp_update_post(
    array(
        'ID' => $image_id, 
        'post_parent' => $new_post_id
    )
);

Just you need to give your category or parent name before the postname in Custom Structure section

本文标签: How to update post parent