Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i've spent way too much time trying to use the wp_insert_post() function a <form> and i do not know why it is not working.

// Create post object
  $my_post = array(
     'post_title' => 'My post',
     'post_content' => 'This is my post.',
     'post_status' => 'publish',
     'post_author' => 1,
     'post_category' => array(8,39)
  );

// Insert the post into the database
  wp_insert_post( $my_post );

I'm probably doing something wrong.

If possible can you please hook this to a form. Thanks verymuch. I just need an example to see what i am doing wrong.

here is a link to where i previously asked. pls don't mark dupe.

share|improve this question
add comment

1 Answer

// Create post object
$my_post = array();
$my_post['post_title']    = 'My post';
$my_post['post_content']  = 'This is my post.';
$my_post['post_status']   = 'publish';
$my_post['post_author']   = 1;
$my_post['post_category'] = array(0);
// Insert the post into the database
wp_insert_post( $my_post );"

This works fine. You code is correct, but it is an problem in the form to send the $_POST data? See on this post for feature informations

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.