thanks @ifdion ..
That is my finally functions.php code
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") {
// Do some minor form validation to make sure there is content
$title = $_POST['title'];
$ordertype = $_POST['ordertype'];
$price = $_POST['price'];
$ordertime = $_POST['ordertime'];
$files = $_FILES['profile-picture'];
// Add the content of the form to $post as an array
$new_post = array(
'post_title' => $title,
'post_content' => $description,
'post_category' => array($_POST['category']), // Usable for custom taxonomies too
'post_status' => 'publish', // Choose: publish, preview, future, draft, etc.
'post_type' => 'post' //'post',page' or use a custom post type if you want to
);
//save the new post
$pid = wp_insert_post($new_post);
add_post_meta($pid, 'ordertype', $ordertype, true);
add_post_meta($pid, 'price', $price, true);
add_post_meta($pid, 'ordertime', $ordertime, true);
$attached_files = attach_uploads($files,$pid);
if($attached_files){
set_post_thumbnail( $pid, $attached_files[0] );
}
wp_redirect(get_permalink($pid)); exit;
//insert taxonomies
}
function attach_uploads($uploads,$post_id = 0){
$files = rearrange($uploads);
if($files[0]['name']==''){
return false;
}
foreach($files as $file){
$upload_file = wp_handle_upload( $file, array('test_form' => false) );
$attachment = array(
'post_mime_type' => $upload_file['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($upload_file['file'])),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $upload_file['file'], $post_id );
$attach_array[] = $attach_id;
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $upload_file['file'] );
wp_update_attachment_metadata( $attach_id, $attach_data );
}
return $attach_array;
}
and this upload [input] in theme..
<input type="file" id="profile-picture" name="profile-picture[]" size="40" multiple />
but if i do submit for form, responding with this error...
Fatal error: Call to undefined function rearrange()
sorry for your time