{"action":"created","issue":{"url":"https://api.github.com/repos/rilwis/meta-box/issues/650","labels_url":"https://api.github.com/repos/rilwis/meta-box/issues/650/labels{/name}","comments_url":"https://api.github.com/repos/rilwis/meta-box/issues/650/comments","events_url":"https://api.github.com/repos/rilwis/meta-box/issues/650/events","html_url":"https://github.com/rilwis/meta-box/issues/650","id":100352274,"number":650,"title":"Meta in a meta box with a file upload is saving to the wrong post ID","user":{"login":"rosswintle","id":1532368,"avatar_url":"https://avatars.githubusercontent.com/u/1532368?v=3","gravatar_id":"","url":"https://api.github.com/users/rosswintle","html_url":"https://github.com/rosswintle","followers_url":"https://api.github.com/users/rosswintle/followers","following_url":"https://api.github.com/users/rosswintle/following{/other_user}","gists_url":"https://api.github.com/users/rosswintle/gists{/gist_id}","starred_url":"https://api.github.com/users/rosswintle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rosswintle/subscriptions","organizations_url":"https://api.github.com/users/rosswintle/orgs","repos_url":"https://api.github.com/users/rosswintle/repos","events_url":"https://api.github.com/users/rosswintle/events{/privacy}","received_events_url":"https://api.github.com/users/rosswintle/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-08-11T16:27:01Z","updated_at":"2015-08-19T01:04:46Z","closed_at":null,"body":"I'm having an issue with a file upload (type => 'file'). After much debugging I discovered that meta values within the same meta_box as my file upload were being attached to the post_id of the uploaded file attachment post, not to the post ID of the post.\r\n\r\nThe diagnosis of this involved hooking into the added_post_meta option and doing:\r\n\r\n`error_log(\"DOING: $object_id $meta_key = $meta_value \\n\", 3, '/home/something/public_html/wp-content/errors.txt');`\r\n\r\nThis printed the following:\r\n\r\n```\r\nDOING: 8019 _edit_lock = 1439308388:1 \r\nDOING: 8019 _edit_last = 1 \r\nDOING: 8019 _edit_lock = 1439308404:1 \r\nDOING: 8019 _edit_lock = 1439308418:1 \r\nDOING: 8021 _wp_attached_file = 2015/08/test.pdf \r\nDOING: 8021 _csc_author = bbrg \r\nDOING: 8021 _csc_year = 2014 \r\nDOING: 8021 _csc_hub = rl \r\nDOING: 8021 _csc_featured = 0 \r\nDOING: 8019 _csc_resource_file = 8021 \r\nDOING: 8019 _csc_resource_thumb = test.jpg\r\nDOING: 8019 _csc_external = 0 \r\nDOING: 8019 _csc_disable_preview = 0 \r\nDOING: 8019 _edit_lock = 1439308423:1 \r\nDOING: 8019 _edit_lock = 1439308424:1 \r\n```\r\n\r\nYou can see that the author, year, hub and features meta are saved to post ID 8021, which is the attachment created by the file upload.\r\n\r\nThe rest of the meta is added to post ID 8019, which is the actual post that I'm saving.\r\n\r\nI've confirmed that this is happening in the database.\r\n\r\nI've had a quick look at file.php in your source code, but can't find anything odd in there.\r\n\r\nHere's my meta box fields definition:\r\n\r\n```\r\n// List of meta fields\r\n\t\t'fields' => array(\r\n\t\t\t// FILE UPLOAD\r\n\t\t\tarray(\r\n\t\t\t\t'name' => 'Upload a resource file',\r\n\t\t\t\t'desc' => 'Upload a resource file here',\r\n\t\t\t\t'id'   => $prefix . 'resource_file',\r\n\t\t\t\t'type' => 'file',\r\n\t\t\t),\t\t\t\r\n\t\t\tarray(\r\n\t\t\t\t'name' => 'Resource URL (optional)',\r\n\t\t\t\t'id' => $prefix . 'resource_URL',\r\n\t\t\t\t'desc' => 'The URL of an external resource (will not be used if a file is uploaded)',\r\n\t\t\t\t'type'  => 'text',\r\n\t\t\t\t'std' => '',\r\n\t\t\t),\r\n\t\t\tarray(\r\n\t\t\t\t'name' => 'Resource Thumbnail URL (optional)',\r\n\t\t\t\t'id' => $prefix . 'resource_thumb',\r\n\t\t\t\t'desc' => 'The URL of a thumbnail (automatically generated from uploaded PDFs)',\r\n\t\t\t\t'type'  => 'text',\r\n\t\t\t\t'std' => '',\r\n\t\t\t),\r\n\t\t\tarray(\r\n\t\t\t\t'name' => 'External/subscription resource',\r\n\t\t\t\t'id' => $prefix . 'external',\r\n\t\t\t\t'desc' => 'Select \"Yes\" to mark the resource as an external or subscription resource. Such resources do not appear in initial search results and have to be requested to be shown.',\r\n\t\t\t\t'type'  => 'select',\r\n\t\t\t\t'options' => array(\r\n\t\t\t\t\t\t\t\t'0' => 'No',\r\n\t\t\t\t\t\t\t\t'1' => 'Yes',\r\n\t\t\t\t\t),\r\n\t\t\t\t'std' => '0',\r\n\t\t\t),\r\n\t\t\tarray(\r\n\t\t\t\t'name' => 'Disable Google Docs Preview',\r\n\t\t\t\t'id' => $prefix . 'disable_preview',\r\n\t\t\t\t'desc' => 'Check this to disable Google Docs preview of the resource - note that the preview only works for certain document types anyway (PDF, DOC, DOCX)',\r\n\t\t\t\t'type'  => 'checkbox',\r\n\t\t\t\t'std' => '',\r\n\t\t\t),\r\n\t\t)\r\n```\r\n\r\nMy hook to do the debug looks like this:\r\n\r\n```\r\nadd_action( \"updated_post_meta\", \"debug_upload\", 10, 4 );\r\nadd_action( \"added_post_meta\", \"debug_upload\", 10, 4 );\r\n\r\nfunction debug_upload( $meta_id, $object_id, $meta_key, $meta_value ) {\r\n\terror_log(\"DOING: $object_id $meta_key = $meta_value \\n\", 3, '/home/name/public_html/wp-content/errors.txt');\r\n}\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/rilwis/meta-box/issues/comments/132407665","html_url":"https://github.com/rilwis/meta-box/issues/650#issuecomment-132407665","issue_url":"https://api.github.com/repos/rilwis/meta-box/issues/650","id":132407665,"user":{"login":"funkedgeek","id":1159774,"avatar_url":"https://avatars.githubusercontent.com/u/1159774?v=3","gravatar_id":"","url":"https://api.github.com/users/funkedgeek","html_url":"https://github.com/funkedgeek","followers_url":"https://api.github.com/users/funkedgeek/followers","following_url":"https://api.github.com/users/funkedgeek/following{/other_user}","gists_url":"https://api.github.com/users/funkedgeek/gists{/gist_id}","starred_url":"https://api.github.com/users/funkedgeek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/funkedgeek/subscriptions","organizations_url":"https://api.github.com/users/funkedgeek/orgs","repos_url":"https://api.github.com/users/funkedgeek/repos","events_url":"https://api.github.com/users/funkedgeek/events{/privacy}","received_events_url":"https://api.github.com/users/funkedgeek/received_events","type":"User","site_admin":false},"created_at":"2015-08-19T01:04:46Z","updated_at":"2015-08-19T01:04:46Z","body":"@rosswintle Has the commit fixed your problem?"}}