Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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) {
  array(1) {
    array(1) {
      string(38) "Content, title, and excerpt are empty."
  array(0) {

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

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Use wp_update_post(), not insert.

        'ID' => $image_id, 
        'post_parent' => $new_post_id
share|improve this answer
Thanks a lot. But in is told that if ID exists - it updates current post... – user1692333 Jan 9 '13 at 22:49
Well, yes, the post_parent information is always stored in the child posts, not in the parent. So you have to update the image (post type attachment) to assign it to a parent post. – toscho Jan 9 '13 at 22:53
so i did this wp_insert_post(array('ID' => $image_id, 'post_parent' => $new_post_id) – user1692333 Jan 9 '13 at 23:15
I know that it's old discussion, but if you use wp_insert_post you need to specify all the fields. The fields that aren't in the arguments are updated with the default values. with wp_update_post you just need to specify the fields you want to change and all the other fields will keep the value. – Ricardo BRGWeb Apr 25 at 13:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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