Note that there are some explanatory texts on larger screens.

plurals
  1. POwoocommerce product gallery images upload from front-end
    primarykey
    data
    text
    <p>i created a code which publish product from front-end issue is when i upload gallery images from frontend only last image upload. </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>here is function multiupload</p> <pre><code> agp_process_image('agp_image_file', $post_id, $result['caption'], $result['content'], $result['author']); 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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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