Using media_handle_upload from the Front-End and Attaching Media to a Post
-
Hi All,
I am trying to design a file upload from the front-end of my wordpress theme and have a small, but annoying issue that I have run into. I am using a custom post type and trying to attach files to this post type. My code for the Form itself and the handler is below.The upload itself works and the media is placed into the correct directory and the media browser but it is NOT attached to any post. I am not sure where I am going wrong here and the code is amazingly brief on media_handle_upload so anyone with experience with this would be awesome….
//************************************** // Attachment Insert Form //************************************** function insert_attachment_form($postID) { ?> <form id="file-form" name="file-form" method="POST" action="" enctype="multipart/form-data" > <input type="file" id="async-upload" name="async-upload" /> <input type="hidden" name="postID" value="<?php echo $post->ID ?>" /> <?php wp_nonce_field('client-file-upload', 'client-file-upload'); ?> <input type="submit" value="Upload" id="submit" name="submit" /> </form> <?php } //************************************** // Process Attachment Form //************************************** function process_attachment() { // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['client-file-upload'], 'client-file-upload') ) { return $post->ID; } // Is the user allowed to edit the post or page? if ( !current_user_can( 'publish_posts', $post->ID )) return $post->ID; if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_FILES )) { require_once(ABSPATH . 'wp-admin/includes/admin.php'); $id = media_handle_upload('async-upload', $_POST['postID']); unset($_FILES); } }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Using media_handle_upload from the Front-End and Attaching Media to a Post’ is closed to new replies.