admin管理员组文章数量:1317906
I am using cmb2 for frontend form submission with custom post type name 'form'. But can not upload image with that. the first step is:
array(
'name' => 'Image',
'type' => 'file',
'id' => '_first_image',
'options' => array(
'url' => true, // Hide the text input for the url
),
'text' => array(
'add_upload_file_text' => 'Upload your image image', // Change upload button text. Default: "Add or Upload File"
),
),
my form is:
<form method="post" action="" id="form">
<div class="student-image">
<label for="student_image">Image</label>
<input name="image" type="file" id="img" accept="image/png, image/jpeg, image/jpg">
</div>
<input style="color: white;" name="submit" type="submit" value="Submit">
</form>
PHP code:
if(isset($_POST['submit'])){
$args = array(
'post_status' => 'draft',
'post_type' => 'form',
'post_author' => $user_ID,
'post_title' => $_POST['name'],
'post_content' => $_POST['subject'],
);
$query = wp_insert_post( $args, false );
$image = $_POST['image'];
if(query){
update_post_meta( $query, '_first_image', $image );
}
}
This is my code. I can't upload any image. what can I do for uploading images and what code do I add to complete. and also add to upload only one image. can any one give me the solution. I am trying other solution but those can't work.
本文标签: custom fieldhow to upload a image from frontend with wpinsertpost and also updatepostmeta
版权声明:本文标题:custom field - how to upload a image from frontend with wp_insert_post and also update_post_meta? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742030211a2416303.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论