Currently I’m working on a project where site is driven by user articles, how it works:
- Any user goes to compose post page
and writes post along with few
details, has upload file option for
image and then submits - Post is uploaded in wordpress and the image attached is set as featured image
- Admin approves the post and it gets published.
Here user is not required to have an account. I am using wp_insert_post
to create a new post but not able to figure out how to add featured image via PHP.
Use the set_post_thumbnail function.
Require you use WordPress 3.1.0 or later.
You need call this function after you have successfully created your post via
wp_insert_post
and have a valid$post_ID
.