我想问题是你的表单标签丢失了enctype="multipart/form-data"
因此,请尝试更改:
<form method="post" action="">
收件人:
<form method="post" action="" enctype="multipart/form-data">
另外,如果要重定向到新创建的post更改,请执行以下操作:
wp_redirect( \'http://domain.com\' );
收件人:
wp_redirect( get_permalink($post_id));
exit();
更新:从评论中我了解到,我希望图像显示在内容中,这是另一回事,但不是那么难,
更改:
if ($attach_id > 0){
//and if you want to set that image as Post then use:
update_post_meta($post_id,\'_thumbnail_id\',$attach_id);
}
收件人:
if ($attach_id > 0){
$post = get_post($post_id,\'ARRAY_A\');
$image = wp_get_attachment_image_src( $attach_id );
$image_tag = \'<img src="\'.$image[0].\'" width="\'.$image[1].\'" height="\'.$image[2].\'" />\';
//add image above the content
$post[\'post_content\'] = $image_tag . $post[\'post_content\'];
//add image under the content
//$post[\'post_content\'] = $post[\'post_content\'] . $image_tag;
$post_id = wp_update_post( $post );
}