Make the uploaded image from form the featured image of post

[ad_1]

Hi there,
I have a working function that create a new post upon submitting a form. I had to add an upload field to this form to let people upload an image that tend to become the post featured image. I’ve tried a lot of things but it seems that I cannot achieve it for now.

What I’d like to know is how can I get the uploaded file id from my website’s library? I think that if I could get the id I could siply use set_post_thumbnail() function to update my post.

I’ve tried $_POST['upload-1']['id']; where upload-1 is the name of my field in the form but I have an error Undefined index: upload-1 in my logs. What is the right way to get the ID of the uploaded image please?

  • This topic was modified 6 hours, 11 minutes ago by clementflib.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer