{"id":9452945,"date":"2017-08-30T05:50:45","date_gmt":"2017-08-30T05:50:45","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/bug-field-of-type-file-does-not-delete-postmeta-properly\/"},"modified":"2017-08-30T05:50:45","modified_gmt":"2017-08-30T05:50:45","slug":"bug-field-of-type-file-does-not-delete-postmeta-properly","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/bug-field-of-type-file-does-not-delete-postmeta-properly\/","title":{"rendered":"Bug: Field of type &#8220;File&#8221; does not delete postmeta properly"},"content":{"rendered":"<p>Hello everyone,<br \/>\nthe issue is reproducible when the user wants to remove the contents of a &#8220;file&#8221; field type and deletes the contents of the input element instead of clicking on the close button attached to the preview image.<\/p>\n<p><strong>Expecting:<\/strong><br \/>\nBoth meta keys (&#8216;my_field&#8217; and &#8216;my_field_id&#8217;) for the file field should be removed<\/p>\n<p><strong>What happens:<\/strong><br \/>\nOnly &#8216;my_field&#8217; meta key is removed from the database while &#8216;my_field_id&#8217; remains<\/p>\n<p><strong>How to reproduce:<\/strong><br \/>\n1. Create a new meta field of type file<br \/>\n2. Add an attachment<br \/>\n3. Save the post<br \/>\n4. Check database for &#8216;my_field&#8217; and &#8216;my_field_id&#8217; post meta<br \/>\n4. Delete the contents of the input field only<br \/>\n5. Save the post<br \/>\n6. Check database again, &#8216;my_field_id&#8217; shall still be there<\/p>\n<p><strong>Example code:<\/strong><\/p>\n<pre><code>        $cmb = new_cmb2_box(\n            [\n                &#039;id&#039; =&gt; &#039;file_test_field&#039;,\n                &#039;title&#039; =&gt; &quot;Test&quot;,\n                &#039;object_types&#039; =&gt; [&#039;post&#039;],\n            ]\n        );\n        $cmb-&gt;add_field(\n            [\n                &#039;id&#039; =&gt; &#039;my_field&#039;,\n                &#039;name&#039; =&gt; &quot;Insert file here, then remove the input only and save the post&quot;,\n                &#039;type&#039; =&gt; &#039;file&#039;,\n            ]\n        );\n<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-9452945","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/9452945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/9452945\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=9452945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}