Note that there are some explanatory texts on larger screens.

plurals
  1. POwp_insert_post multi upload Images
    text
    copied!<p>Hi i want to upload multiple images with wp_insert_post but only last image of multiple upload insert there other images upload but din't attach there .... </p> <p>here is code </p> <pre><code>&lt;form action="#" method="post" enctype="multipart/form-data"&gt; &lt;input type="file" name="agp_gallery[]" id="agp_image_files" style="width:90%; margin-left:5px;" multiple&gt; </code></pre> <p></p> <p>here is function multiupload </p> <pre><code> if ( $_FILES ) { $files = $_FILES['agp_gallery']; foreach ($files['name'] as $key =&gt; $value) { if ($files['name'][$key]) { $file = array( 'name' =&gt; $files['name'][$key], 'type' =&gt; $files['type'][$key], 'tmp_name' =&gt; $files['tmp_name'][$key], 'error' =&gt; $files['error'][$key], 'size' =&gt; $files['size'][$key] ); $_FILES = array("agp_gallery" =&gt; $file); foreach ($_FILES as $file =&gt; $array) { agp_process_wooimage($file, $post_id, $result['caption']); } } } } </code></pre> <p>here is main function </p> <pre><code>function agp_process_wooimage($file, $post_id, $caption){ if ($_FILES[$file]['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'); $attachment_id = media_handle_upload($file, $post_id); update_post_meta($post_id, '_product_image_gallery', $attachment_id); $attachment_data = array( 'ID' =&gt; $attachment_id, 'post_excerpt' =&gt; $caption ); wp_update_post($attachment_data); return $attachment_id; } </code></pre> <p>i get this above code from here:-</p> <p><a href="http://madebyraygun.com/blog/2012/upload-and-attach-multiple-images-from-the-wordpress-front-end/" rel="nofollow">http://madebyraygun.com/blog/2012/upload-and-attach-multiple-images-from-the-wordpress-front-end/</a></p> <p>and </p> <p>all code here :- </p> <p><a href="http://wp.tutsplus.com/tutorials/allow-users-to-submit-images-your-site/" rel="nofollow">http://wp.tutsplus.com/tutorials/allow-users-to-submit-images-your-site/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload