I am trying to do something similar to the above question. I am trying to make users post and upload images from front-end. I have already done the post form and its working.
I just followed and tried the answer posted by Robin I Knight upload-post-thumbnail-from-the-front-end. Sadly i couldn’t get it to work. Is there anything i’m suppose to change or edit?
Thank you.
If you are talking about the answer i posted here
its simply uploading file in an iframe to achieve “Ajax like” submit.
Now if you already have a form that handles the post submit you can simply add the upload file field input somewhere in your form:
make sure that your form has
enctype="multipart/form-data"
attribute.then in your form processing script after you create the post (assuming that you are using
wp_insert_post();
)keep hold of the post ID in a new var:
and after that add:
and you image will be uploaded and saved as post thumbnail.
HTML Markup:
Uploading the image: