处理表单时,我希望将值插入自定义帖子类型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
。
任何帮助非常感谢。一个例子就是很棒。
答案 0 :(得分:0)
请替换此行
$ art_upload = $ _FILE [' art_upload'] [$ i];
到
$ art_upload = $ _FILES [' art_upload'] [$ i];