itredsea
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
Forum: Plugins
In reply to: [SpeakUp! Email Petitions] Edit Post Code to Zip Code@lewismichaelhansen congratulate, I see you solve it, HOW????
Same problem here also ?
“For security reasons, you must pass the remote ip to reCAPTCHA”Forum: Plugins
In reply to: Upload files from front-endI am working in that too, BUT…
When I add in functions.php this code<?php function insert_attachment($file, $post_id, $setthumb = 'false') { // check to make sure its a successful upload if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) __return_false(); $post_id = $_POST['post_id']; 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, $post_id); if ($setthumb) update_post_meta($post_id, '_thumbnail_id', $attach_id); return $attach_id; } ?>
And in the home.php after wp_insert_post part I add
$wp_filetype = wp_check_filetype(basename($file), null); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', basename($file)), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment($attachment, $file, $post_id); // you must first include the image.php file // for the function wp_generate_attachment_metadata() to work require_once(ABSPATH . "wp-admin" . '/includes/image.php'); $attach_data = wp_generate_attachment_metadata($attach_id, $file); wp_update_attachment_metadata($attach_id, $attach_data);
Now I get a file uploaded in the media admin page and attached to it’s custom-post.
But the file is not an image and in the front page Comes ” Missing Attachment “I get tired and mad after ten days work in that, Can any body help please?
Viewing 3 replies - 1 through 3 (of 3 total)