Php wordpress,在自定义帖子类型中插入值无效

Php wordpress,在自定义帖子类型中插入值无效,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,在处理表单时,我希望将值插入到自定义post类型产品中 以下是我迄今为止所做的工作 $art_title = $_POST['art_title']; $i = 0; foreach($art_title as $value) { $art_title = $_POST['art_title'][$i]; $art_width = $_POST['art_width'][$i]; $art_height = $_POST['art_height'][$

在处理表单时,我希望将值插入到自定义post类型产品中

以下是我迄今为止所做的工作

 $art_title = $_POST['art_title'];

    $i = 0;
    foreach($art_title as $value) {
    $art_title = $_POST['art_title'][$i];
    $art_width = $_POST['art_width'][$i];
    $art_height = $_POST['art_height'][$i];
    $art_price = $_POST['art_price'][$i];
    $art_creation_date = $_POST['art_creation_date'][$i];
 $art_upload = $_FILE['art_upload'][$i];

       // Add the content of the form to $post as an array
        $new_post = array(
            'post_title'    => $art_title,
            'post_status'   => 'draft',    
            'post_type' => 'products'
        );
        //save the new post
        $pid = wp_insert_post($new_post); 
        $attachment_id = media_handle_upload( 'art_upload', $pid );

        if ( is_wp_error( $attachment_id ) ) {
            // There was an error uploading the image.
        } else {
            // The image was uploaded successfully!
        }

    $i++;
    }
我使用了媒体处理上传和帖子id,但这不起作用

我想知道的是,如何将这些$\u POST值与图像一起作为产品图像插入到自定义POST类型产品中

自定义帖子类型为woocommerce产品


非常感谢您的帮助。举个例子就好了。

请替换这一行

$art_upload=$_文件['art_upload'][$i]

$art_upload=$_文件['art_upload'][$i]