can someone give me please a code for image upload ? i try many but no one works , this is what i have :
$post = array(
'comment_status' => $comment_status,
'ping_status' => 'open',
'post_author' => $user_id,
'post_content' => '',
'post_status' => $status,
'post_title' => $title,
'post_type' => 'post',
);
$post_id = wp_insert_post($post);
if($_FILES['image_imagepost']['error'] == 0) {
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 = ( $file_handler, $post_id );
if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);
return $attach_id;
}
I try to make a post and upload a image,the post is ok but the image didin't upload on media. Thanks.