0

I need to somehow create a form in which the user could fill in several fields and select an image that would be added to the post,

The post would be formated from the input fields and I can do that just fine, but my problem is, I've done this before, soem tiem ago and can't remember how to assign a post to the correct category and also upload/assign the image via WP functions?

Any help would be great!

1 Answer 1

1

To insert a post...

wp_insert_post($postarr, $wp_error = false)

The code's in wp-includes/post.php.

To insert an image...

media_handle_upload($file_id, $post_id, 
   $post_data = array(), $overrides = array( 'test_form' => false ))

$file_id is the index in $_FILES. $post_id is the post that you want to attach the file to.

That code's in wp-admin/includes/media.php, which might pose a problem if you are doing this on the front end rather than in the admin.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.