The field id has to match in both function so if your field id is foo
the when you save you need to look for that id and when you save a checkbox field its smart to remove it if not set so:
function image_attachment_fields_to_save($post, $attachment) {
if( isset($attachment['foo']) ){
update_post_meta($post['ID'], 'foo', $attachment['foo']);
}else{
delete_post_meta($post['ID'], 'foo' );
}
return $post;
}
add_filter("attachment_fields_to_save", "image_attachment_fields_to_save", null, 2);
Related Posts:
- Saving Custom Field in Attachment Window in WordPress 3.5
- Insert attachment ID in custom field from media uploader
- How can I store a file in the database in the same way WordPress and ACF do?
- Remove Dimension from wp_get_attachment_image
- explode array within shortcode
- How can I append custom data to images in the editor?
- How can I remove fields in the attachment editor?
- Using media-upload.php to upload mp3 via custom fields
- Extend WP Customizer to make multiple image selection possible
- Add multiple images to a page sidebar
- How to set a default meta value for custom field
- Add custom field to image editor
- How to save custom fields for attachments
- Display info from custom fields in all images’ HTML
- WordPress custom upload field error
- copy attachments to another post type and change attachment url
- limit amount of photos uploaded per cpt post
- ajax delete value from custom field array
- Save attachment custom fields on front end
- Metabox with multiple fields added by user and upload box
- Metabox image upload and custom field
- Custom image sizes for custom field media uploads
- wp_handle_upload error “Specified file failed upload test” but still creates attachment?
- How to save media files under custom folder without changing wp-config.php or changing media settings
- Getting the ID of any image for use in functions.php
- Validate data on attachment_fields_to_save
- Custom field not updating when value is empty
- how to upload a image from frontend with wp_insert_post and also update_post_meta?
- Is there a simpler version of WP Media?
- Client PDF Upload (Catalogue) – Automatically update link to PDF
- How to add upload video option in wordpress for user?
- Uploading PDF using Media Uploader
- Select multiple images from custom field
- Link FROM attachment to full post and get custom fields values on attachment page?
- WordPress Media Uploader custom Javascript not working
- Attach images to posts using custom fields (just paths to images already uploaded)
- How to use media upload on metabox post page without breaking TinyMCE?
- Front-End User Profile
- Show custom field on attachment page?
- Save attachment ID instead of URL in custom field
- Image upload and path to custom field
- How to delete file uploaded by Plupload
- Problem uploading different files as custom fields with front end post form
- How do I upload file through custom field, save it to database and get it
- Shortcode for Custom Field of Media Attachment (to use with Featured Images)
- Custom field in media library not saving, selected() function not adding “selected” to select list input type
- Can you generate a featured image from two images from custom fields?
- want to add video upload option for front end user
- How to delete attachments associated with custom field type when post property changes? [closed]
- display custom media folders to wordpress media popup
- Custom Meta Boxes and Fields for WordPress: Change directory upload based on user-edit page
- Change path to child of page when uploading image via custom field
- Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
- How can I create more “create attachment” custom field – any idea?
- Adding thumbnails for non-image attachments
- Upload image to wordpress
- Multiple image uploader under editor?
- unlink() doesn’t delete the uploaded file
- How can I attach files without using a plugin?
- Save Custom Meta Value on Media Upload
- Query Posts based on custom field value
- How to format the various types of custom fields?
- Problem saving meta data
- How to properly get popular Posts by multiple Values
- Admin – Search Events by a custom field
- How to add a default field Name to post Custom Fields
- Get file size from ACF repeater field
- Automatically set the_post_thumbnail to Custom Field Value
- create a custom field that let me include other posts
- Append custom field items to content from plugin
- Redirecting to an external URL
- Check if value exists before saving
- Echo out custom fields in comments
- Using ACF Custom Field value in a URL with do_shortcode() [closed]
- Get meta value when the page is a blog archive
- Saving and using Custom Field in user settings/profile “Checkbox list”
- Why WordPress takes time to make request to save post?
- Text in header as a page – hide from Web crawlers
- Custom Metabox Always shows box and checked
- Show comon custom field results?
- Search one custom field?
- Can’t save meta field value if the title not set
- Create custom query for search?
- Add Image With Changeable Link in Custom Field [closed]
- update_user_meta(): invisible data storage
- Get a different meta value with ajax when different elements are clicked
- Extend WP_User_Query or WP_User to return all custom fields?
- Display Data From This Custom Media Upload Meta Box?
- Quicktag button to automatically add a custom field to a post
- Delete custom fields on post publish?
- display Flexible Fields from options
- Sort custom fields in admin by last field added
- Display custom fields only if it has a value
- Custom fields and auto save
- After I upload a file to library its name converted to dashes
- Save values generated via API as custom meta fields
- Extra text’n’image field in a page
- Ordering posts by custom fields
- Get first URL from custom field, download and set as featured image on post publish
- Query postmeta values, and return multiple post_titles for common meta value