处理表单时,我希望将值插入到自定义帖子类型products
中。
这是我到目前为止所做的
$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++;
}
我media_handle_upload和帖子 ID 一起使用,但这不起作用。
我想知道的是如何将这些 $_POST 值与图像一起插入自定义帖子类型products
product_image
?
自定义帖子类型是 wooCommerce products
。
任何帮助非常感谢。一个例子会很棒。
请替换此行
$art_upload = $_FILE['art_upload'][$i];
自
$art_upload = $_FILES['art_upload'][$i];