I have currently added a custom meta field to upload a media file (image). I can successfully add the upload button to display and it works but I'm having problems saving the field when updating the page.
Code I'm using to create and display the field:
<?php
$image = get_template_directory_uri().'/images/image.png';
echo '<span class="custom_default_image" style="display:none">'.$image.'</span>';
if ($meta)
{
$image = wp_get_attachment_image_src($meta, 'medium'); $image = $image[0];
}
echo '<input name="image-upload-one" type="hidden" class="custom_upload_image value="'.$meta.'" />
<img src="'.$image.'" class="custom_preview_image" alt="" />
<br />
<input class="custom_upload_image_button button" type="button" value="Choose Image" />
<br/>
<small>
<a href="#" class="custom_clear_image_button">Remove Image</a>
</small>
<br clear="all" />
<span class="description">'.$field['desc'].'</span>'; ?>
The above code is from: http://code.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-3-extra-fields--wp-23821 I can't find a way to save the input.
I've created simple text fields/texttext area fields and can save them no problem using the function below but having problems saving image fields:
<?php if (isset($_POST['text-two']))
{
update_post_meta($post_id,'textTwo', esc_attr($_POST['text-two']));
} ?>
Any help much appreciated.