Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 添加元后创建多个元键_Image_Wordpress_Upload - Fatal编程技术网

Image 添加元后创建多个元键

Image 添加元后创建多个元键,image,wordpress,upload,Image,Wordpress,Upload,您好,我创建了一个上传功能,但有一个问题添加\ u post\ u meta创建多个meta\ u键而不是一个 示例:- meta_键meta_值 _product_image_gallery 1 _product_image_gallery 2 _product_image_gallery 3 _product_image_gallery 1,2,3 if ( $_FILES ) { $files = $_FILES['agp_gallery']; foreach

您好,我创建了一个上传功能,但有一个问题添加\ u post\ u meta创建多个meta\ u键而不是一个

示例:-

meta_键meta_值

_product_image_gallery 1
_product_image_gallery 2
_product_image_gallery 3 
_product_image_gallery 1,2,3


if ( $_FILES )

{

    $files = $_FILES['agp_gallery'];

    foreach ($files['name'] as $key => $value)

    {

        if ($files['name'][$key])

        {

            $file = array(

            'name' => $files['name'][$key],

            'type' => $files['type'][$key],

            'tmp_name' => $files['tmp_name'][$key],

            'error' => $files['error'][$key],

            'size' => $files['size'][$key]

            );

        }

        $_FILES = array("agp_gallery" => $file);

        $i=1;

        foreach ($_FILES as $file => $array)

        {

            $newupload = agp_process_wooimage($file,$post_id,$i);

            $i++;

        }

    }

}
它应该是

meta_键meta_值

_product_image_gallery 1
_product_image_gallery 2
_product_image_gallery 3 
_product_image_gallery 1,2,3


if ( $_FILES )

{

    $files = $_FILES['agp_gallery'];

    foreach ($files['name'] as $key => $value)

    {

        if ($files['name'][$key])

        {

            $file = array(

            'name' => $files['name'][$key],

            'type' => $files['type'][$key],

            'tmp_name' => $files['tmp_name'][$key],

            'error' => $files['error'][$key],

            'size' => $files['size'][$key]

            );

        }

        $_FILES = array("agp_gallery" => $file);

        $i=1;

        foreach ($_FILES as $file => $array)

        {

            $newupload = agp_process_wooimage($file,$post_id,$i);

            $i++;

        }

    }

}


对于每个循环,调用media\u handle\u upload()并向其传递一个新的$文件。我认为这将为每个文件创建一个新的附件ID

然后在update_post_meta()中使用,如果不存在,则此函数默认使用add_post_meta()。但不会,因为你还没有在帖子中添加特定的附件

我会看到这个脚本按预期工作,您的问题可能遗漏了一些东西。您是否要求将多个图像添加到单个meta_值