Here is how I’ve done it. No changes to the save function are needed. I’ve been trying to save data from both fields at once, thats why it didn’t worked.
<input class="upload_file" type="text" size="45" id="picture_%1$s" name="picture_%1$s" value="%6$s" />
<input class="upload_button button" type="button" value="Upload File" />
<input class="upload_file_id" type="hidden" id="picture_%1$s_id" name="items[%1$s][picture]" value="%7$s" />
The value stored in .upload_file_id
is attachment ID (%7$s
== item['picture']
).
The value displayed in .upload_file
(%6$s
) is wp_get_attachment_image_src
like so:
$img = wp_get_attachment_image_src($item['picture']);
$img = $img[0];
And then we set %6$s
to be $img
. So in database just the attachment ID is stored, and we display link using WordPress function.
Related Posts:
- 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
- limit amount of photos uploaded per cpt post
- Metabox image upload and custom field
- wp_handle_upload error “Specified file failed upload test” but still creates attachment?
- Select multiple images from custom field
- How to use media upload on metabox post page without breaking TinyMCE?
- Image upload and path to custom field
- 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
- Upload image to wordpress
- Multiple image uploader under editor?
- How can I add an image upload field directly to a custom write panel?
- Custom field/meta populated by dropdown of existing posts?
- Remove Dimension from wp_get_attachment_image
- What is the index [0] for on post meta fields?
- Individual Widgets per Page
- Gutenberg add a custom metabox to default blocks
- ‘Preview Changes’ for custom meta boxes?
- Using TinyMce with textareas in meta boxes on custom post types
- add meta box – custom field : which to choose?
- Add metabox to document tab in gutenberg
- How to add add_meta_box to specific Page Template?
- Custom field metabox not showing in back-end
- Upload multiple images in a custom metabox
- How to hide meta box values from custom fields list?
- Change wp_get_attachment_image attributes (src and srcset) on specific custom field
- Adding another state (spam, reject, approve) to wordpress comments?
- How do I make a custom field choose an image?
- Adding upload button in metabox
- Arrange custom fields with drag and drop?
- How can I avoid re-inventing the Custom Fields wheel in my Plugin’s Metabox?
- Unable to get Preview of Uploaded image within a Custom Meta box
- extend Meta Box / Document Panel
- Saving Custom Field in Attachment Window in WordPress 3.5
- Add custom option to Standard Page Attributes Meta Box
- How to store the value of a custom field dropdown select for post referencing?
- Only show metabox when date-value in other metabox is over?
- Custom Meta Boxes: Store two values in one repeatable field
- Display thumbnail from custom field
- Add custom field to image editor
- Populating meta box with select-list of existing posts, and assigning it to custom post types
- Create meta boxes that don’t show in custom fields
- How To Create a Metabox of HTML Content with Instructions For Editors When Editing a Post or Page?
- How to load php file for specific page in admin?
- How to set default metaboxes on user creation?
- Display info from custom fields in all images’ HTML
- Metabox nonce PHP notice
- TinyMCE in Custom Metabox not loaded after upgrading from WP 3.1.4 to WP 3.2
- wp_editor in add_meta_boxes does not show gallery
- WordPress custom upload field error
- How do I assign this filter to a variable? (Appending php & markup to the_content)
- Problem in custom meta boxes
- Multiplile values checkbox or select in custom meta box
- Create custom field key upon theme activation
- automatically set “Featured Image” the same as the og:i that is set in a custom field
- copy attachments to another post type and change attachment url
- Problem with adding exta field in metabox in custom post type
- Adding a custom field or metabox to the post-thumbnail widget?
- Custom fields to save multiple values
- I need a Simple image uploader with a simple screen. WP default has too many options.
- How do I add custom_meta_box_id’s value?
- Undefined index error when saving content on metabox
- How to save multiple metaboxes?
- add meta box using function.php
- all tincymce’s switch when updating page after changing from html to text in custom metabox
- My metabox class
- Custom image sizes for custom field media uploads
- How to construct multiple meta boxes
- Add WYSIWYG to Image Description field
- Loading scripts to the Post Edit page only
- Force hide custom field metaboxes
- Woocommerce with metabox plugin
- Insert attachment ID in custom field from media uploader
- Get Meta from Custom Field of Image URL
- wp_editor removes paragraph from custom meta box
- How to Display Custom Meta Box only on Specific Page IDs
- Add url from Custom Field as ‘Featured Image’. Code not working
- WP Custom Fields Metabox Disappears – ACF plugin issue [closed]
- Metabox will not save
- window.send_to_editor and jQuery .attr() conflicts with multiple custom upload image meta boxes
- How to save media files under custom folder without changing wp-config.php or changing media settings
- How to check for specific meta box value on front end and output accordingly
- Where did the Add New Custom Field go?
- How Meta Data is different from Custom Fields of POST/PAGE in WordPress
- How can I store a file in the database in the same way WordPress and ACF do?
- Admin meta Image Path
- Tweak Meta for Post to work it for Pages also
- Odd PHP Code To Display HTML Of Meta Box [closed]
- How to display multiple images in custom field
- custom field not saved
- How to create a Custom Meta Box with Name/Value Admin User Input Fields?
- Create Multiple File Upload Metabox in WordPress
- Get image post ID in media upload
- Users Select inside custom metabox
- Custom Metabox Not Saving
- Better Method for Multiple Meta Boxes
- How to add image attachment to post from a single meta key (Woocommerce)
- how to fetch the meta field keys/meta boxes from a post type?