I have a custom-type post I’m trying to attach some audio/wav files to using the wp-admin UI.

When I upload the new files using the Add Media popup those get saved and embedded into the post just fine, but in the database those attachment-posts have parent_post set to 0.

It records the post_date and post_author correctly, but not the post_parent.

What is the reason for that behavior and how can I fix it?

Update ok so this only happens to the posts with custom post-type. When I upload the same audio file to the normal post it gets attached properly. If I try disabling the plugins it will remove that custom post type I’m working with and I won’t be able to test.

Update2 this happens during the upload process. Here’s the var_dump($_REQUEST); output from wp-admin/async-upload.php when uploading an attachment to the regular post:

array(4) {
  ["name"]=>
  string(42) "my_file.wav"
  ["action"]=>
  string(17) "upload-attachment"
  ["_wpnonce"]=>
  string(10) "457d8c9ee7"
  ["post_id"]=>
  string(4) "1234"
}

The post_id key is missing when I’m uploading an attachment to the custom post.

1 Answer
1

The reason was the post_id key simply missing from the upload query.

It was there for the normal posts, but was being omitted in the custom-post-type uploads.
No idea why. The issue had something to do with the javascript uploader settings.

So I’ve asked another question regarding the pluploader here and have managed to find the solution myself.

I do not know why was the post_id being excluded, but at least it works now.

Leave a Reply

Your email address will not be published. Required fields are marked *