我找到了一个有效的解决方案。这将通过将上载的文件附加到帖子并在循环中显示来处理这些文件。仍然没有设置特征图像。
if ( $_FILES ) {
foreach ( $_FILES as $file => $array ) {
$newupload = insert_attachment( $file, $pid_buy );
}
}
function insert_attachment( $file_handler, $post_id, $setthumb=\'false\' ) {
if ( $_FILES[$file_handler][\'error\'] !== UPLOAD_ERR_OK ) {
__return_false();
}
require_once( ABSPATH . "wp-admin" . \'/includes/image.php\' );
require_once( ABSPATH . "wp-admin" . \'/includes/file.php\' );
require_once( ABSPATH . "wp-admin" . \'/includes/media.php\' );
$attach_id = media_handle_upload( $file_handler, $post_id );
return $attach_id;
}
function show_all_thumbs() { // displaying the attached thumbs
global $post;
$post = get_post( $post );
/* image code */
$images =& get_children( \'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent=\' . $post->ID );
if ( $images ){
foreach ( $images as $imageID => $imagePost ){
unset( $the_b_img );
$the_b_img = wp_get_attachment_image( $imageID, \'thumbnail\', false );
$thumblist .= \'<a href="\'.get_attachment_link($imageID).\'">\'.$the_b_img.\'</a>\';
}
}
return $thumblist;
}