You are checking if the field is empty. Try to update it if its empty as well
if( trim( $attachment[ $field ] ) == '' ) $post[ 'errors' ][ $field ][ 'errors' ][] = __( 'Error! Something went wrong.' );
else update_post_meta( $post[ 'ID' ], $key, $attachment[ $field ] );
Try
if( isset( $attachment[ $field ] ) ) {
if( trim( $attachment[ $field ] ) == '' )
$post[ 'errors' ][ $field ][ 'errors' ][] = __( 'Error! Something went wrong.' );
endif;
update_post_meta( $post[ 'ID' ], $key, $attachment[ $field ] );
}
Related Posts:
- Display info from custom fields in all images’ HTML
- copy attachments to another post type and change attachment url
- ajax delete value from custom field array
- Save attachment custom fields on front end
- Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
- Can I exclude a post by meta key using pre_get_posts function?
- What is the index [0] for on post meta fields?
- Best way to programmatically remove a category/term from a post
- Custom field metabox not showing in back-end
- So much data in postmeta
- How to hide meta box values from custom fields list?
- get_post_meta() unserialize issue – returns boolean(false)
- What is the advantage of the wp_options design pattern?
- How can I remove fields in the attachment editor?
- display specific custom fields
- Meta keywords and descriptions plugin for manually editing meta for each page/post
- Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
- Up/Down voting system for WordPress
- post meta data clearing on autosave
- Create custom field on post draft or publish?
- Update meta values with AJAX
- Cannot edit post meta fields with rest API
- Add a post meta key and value only if it does not exist on the post
- Custom fields to save multiple values
- Function to change meta value in database for each post
- wp_handle_upload error “Specified file failed upload test” but still creates attachment?
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- Saving custom image meta fields
- Get all meta keys assigned to a post type
- using multiple meta_key and meta_value in query_posts
- Adding custom fields (post meta) before/during wp_insert_post()
- How to query posts with certain custom meta data, and output Post data
- ACF: How to get the full field name (meta_key) by a field key?
- post meta getting deleted on save
- How to add a new meta key and assign timestamp to posts
- Validate data on attachment_fields_to_save
- meta_compare seems to be treating values as strings instead of integers as expected
- Limit the number of acf content when displaying in post loop [closed]
- Read / Watch / Listen times – meta
- How to add custom metadata text box dropdown to sidebar in Gutenberg editor for all post types
- How do I Implement Atomic Update of Post Metadata?
- Why is my Custom Meta Box Field Inputs NOT saving?
- Get registered custom fields or post meta even if empty
- Displaying multiple URLs as custom field values
- Show values of custom post meta on ‘Add new post’ page?
- Custom post meta field effect on the performance on the post
- Limits, not all post are showen when querying for posts by view count
- Display Custom Meta Box Field Only If Value is Present
- Stop sending email everytime I updates my post
- Best way to store everyday post views?
- shortcode in a custom metabox
- Unable to get specific value from post meta
- Problem with saving large amount of data in postmeta/usermeta
- Custom meta is not being saved
- Link FROM attachment to full post and get custom fields values on attachment page?
- How to get posts with a metadata numeric key greater than X?
- IF Custom field value equals ZERO
- How to use media upload on metabox post page without breaking TinyMCE?
- Let’s Create Custom Field Template Documentation
- Branch made by several custom values
- Looping inside block return
- WordPress creates new lines in postmeta table on post update
- User customising position of WordPress Featured Image
- Can I save post meta programatically without setting metaboxes?
- Insert image into sub-field with update_post_meta
- Show custom field on attachment page?
- How to use conditional statement with custom field
- Save attachment ID instead of URL in custom field
- Meta box values are displayed on Custom Fields list. Is it possible to hide them?
- Best way to achieve multiple links in a post title
- Display Meta Data with HTML?
- How can I add/update post meta in a admin menu page?
- Get author total post votes from post meta
- Group Posts By Custom Meta Value: Date
- custom filed from post in the side bar
- How to display custom fields in hestia theme
- 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
- How to speed up post list slowed by update_meta_cache()?
- WordPress Blocks, setAttributes not saving
- Adding Facebook’s image and meta description retrieval capabilities to a WordPress post
- SQL query to change the value of a Custom Field
- Custom meta POST request fired twice when updating a post in Gutenberg
- Add custom field information to source meta data
- Update custom field on page specific to logged in user
- Create Meta boxes dynamically
- How to delete attachments associated with custom field type when post property changes? [closed]
- Delete custom meta
- Problem saving meta data
- Check if value exists before saving
- Get meta value when the page is a blog archive
- change attachment custom field onChange event
- wordpress simple post multi rating with post_meta and user_meta
- wp_postmeta are updated for only one page
- Custom fields / meta box output
- How can I attach files without using a plugin?
- Colecting values from custom field checkboxes and displaying them in the post
- Build Array from Input Fields question
- How can i put a custom field inside this php
- get Custom field label (select/dropdown) on front end