this question has been answered on stackoverflow. here is a link https://stackoverflow.com/questions/4321914/wp-insert-post-with-a-form/4321975#4321975
i'm trying to let users post to my site by using the wp_insert_post()
function..
<?php $postTitle = $_POST['post_title'];
$post = $_POST['post'];
$submit = $_POST['submit'];
if(isset($submit)){
global $user_ID;
$new_post = array(
'post_title' => $postTitle,
'post_content' => $post,
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(7,100)
);
wp_insert_post($new_post);
}
?>
I got this hooked up to a form on a category page
<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post" cols="66" id="text-desc"></textarea>
<input type="hidden" name="cat" value="7,100"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
I don't know what id did wrong..it's not working. any ideas? thanks
wp_insert_post()
? Could you addvar_dump()
around it? It returns the new ID if succesful, and aWP_Error
on failure. The latter should contain an error message.var_dump(__LINE__)
in thewp_insert_post()
function, at various places, to find out until where the code executes. It should print out line numbers, and if it stops, you know the followingvar_dump()
is not reached. Repeat as necessary to pinpoint the problem. We need more specific information to be able to help you.