Image 添加元后创建多个元键
您好,我创建了一个上传功能,但有一个问题添加\ u post\ u meta创建多个meta\ u键而不是一个 示例:- meta_键meta_值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
_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_值