处理表单时,我希望将值插入到自定义帖子类型中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];
// 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[$i]\', $pid );
if ( is_wp_error( $attachment_id ) ) {
// There was an error uploading the image.
} else {
// The image was uploaded successfully!
}
$i++;
}
我使用了media\\u handle\\u upload和帖子id,但这不起作用。
我想知道的是如何将这些$\\u POST值插入到自定义POST类型中products
与图像一起显示为product_image
?
自定义帖子类型为woocommerceproducts
.
非常感谢您的帮助。举个例子就好了。