0

I'm using a front-end form and wp_insert_post to update posts from the front-end of a website - in order to do this I am using:

'ID' => get_the_ID(),

to make sure it is updating the current post (the form appears on the posts page). I am using the below to edit the post content:

'post_content' => $_POST['postContent'],

(this takes the result from a submitted form).

However, on save the information is submitted in to the post but all other post data seems to be reset such as the title and post password.

Is there any way to stop this happening? it seems like some very odd default functionality.

  • Post all of the relevant code please. – s_ha_dum Jun 9 '14 at 14:23
  • Please see edit. – user319940 Jun 9 '14 at 14:26
  • 1
    You probably want wp_update_post but I don't have time to replicate the problem and try to test it. – s_ha_dum Jun 9 '14 at 14:31
  • Doh! You are correct - glad it's such a simple thing. Pop this as the answer and I'll accept :). – user319940 Jun 9 '14 at 14:40
1

You are using the wrong function. wp_insert_post() is for creating posts. You need wp_update_post() if you want to update existing data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.