I'm working on a plugin to allow a user to post an attachment to their own page(s) in the front it. Everything is working, but I want to also allow the form to have a "Title" field and store that in the DB. I have the field to fill in, but not exactly sure how to save the attachment Title.
I hope that makes since. Here is the code and the form:
echo '<form name="s8-wpfs-form" id="s8-wpfs-form" method="POST" action="" enctype="multipart/form-data">';
echo '<label for="title">Title</label>';
echo '<input type="text" name="title" id="title">';
echo '<label for="uploaded_attachment">Attachment</label>';
echo '<input type="file" name="uploaded_attachment">';
echo '<input type="submit" value="Upload" id="submit" name="submit" />';
wp_nonce_field('client-file-upload', 'client-file-upload');
echo '</form>';
Here is the code that works and uploads the file, but does not store the Title of the attachment:
function insert_attachment($file_handler,$post_id,$setthumb='false') {
// check to make sure its a successful upload
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attach_id = media_handle_upload($file_handler, $post_id);
if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);
return $attach_id;
}
Any direction would help.