Take the 2-minute tour ×
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 codex.wordpress.org/Function_Reference/wp_insert_post 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

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.