front-end attaching image to post (create gallery tab in media uploader)
-
Been searching for a couple of hours and couldn’t find anything.
So I am using wp_editor() to create an easy way to post on the front end. When users upload images through the media uploader they do not attach to the post they are creating and I would really like this.
Images are uploaded before the wp_editor() get processed. I just don’t know how to pass the post’s id to the images that are being uploaded. I want there to be a gallery in the media uploader for each post where there are images uploaded with it like in the backend, so I don’t want to use a custom field. I’d rather have the post’s id passed into the image’s attachment metadata as the
post_parent
, but I can’t figure out how to do this while or after the image uploads or even after the wp_editor processes. I know there is attachment meta because I see that there is an author and date in the media library. When I try towp_update_attachment_metadata
I find that I cannot pass the drafted post id back to my plugin where there is a wp_insert_post hook looking for an ‘inherit’ post status. All of the examples I find online of attaching media uploads to post deal with building your own upload form, not hooking into the media uploader.So is there any other way that I should be doing this? Do I really just need to make custom meta and create my own gallery tab in the media uploader? Is there a way to already have the wp_editor associated with a post id before processing it? Below is my code:
In my plugin (plugin page): obviously this doesn’t really work because I’m not passing any variable back, but maybe it will work if someone can tell me how to pass a variable back:
add_action('wp_insert_post', array(&$this, 'process_images')); function process_images($results){ //global $emptynew; if($results['post_status'] == 'inherit'){ $attachment = array( 'post_parent' => $emptynew, ); wp_update_attachment_metadata( $results['ID'], $attachment ); }; }
In my page where people post (theme page)
get_currentuserinfo(); $loggedInNow = $current_user->ID; $emptynew = wp_insert_post(array( 'comment_status' => 'closed', 'post_title' => 'waiting to be edited by user '.$loggedInNow, 'post_content' => '', 'post_author' => $loggedInNow, 'post_status' => 'draft', 'post_type' => 'post', ) ); <form action="<?php echo home_url('/').'thank-you/'; ?>" method="post"> <label for="title">Title: </label><input size="80" type="text" name="postTitle" /><br /> <?php wp_editor($contentFromPage, 'responsesubmit', $settings = array('media_buttons' => true)); ?> <input type="hidden" name="postempty" value="<?php echo $emptynew; ?>" /> <br /><input type="submit" value="Submit" /> </form>
In the page where the post is processed (theme page)
<?php //information sent from the response pages that have the template Response Template page get_currentuserinfo(); $loggedInNow = $current_user->ID; $response = wp_insert_post(array( 'ID' => $_POST['postempty'], 'comment_status' => 'closed', 'post_title' => $_POST['postTitle'], 'post_content' => $_POST['responsesubmit'], 'post_author' => $loggedInNow, 'post_status' => 'publish', 'post_type' => 'post' );
- The topic ‘front-end attaching image to post (create gallery tab in media uploader)’ is closed to new replies.